Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- running out of memory building massive string
- byte[] bytes = File.ReadAllBytes(infile);
- try
- {
- StringBuilder sb = new StringBuilder(BitConverter.ToString(bytes)); // <--exception
- hexfield.Text = sb.ToString();
- }
- catch(Exception e)
- {
- MessageBox.Show(e.ToString());
- }
- System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
- at System.String.CtorCharArrayStartLength(Char[] value, Int32 startIndex, Int32 length)
- at System.BitConverter.ToString(Byte[] value, Int32 startIndex, Int32 length)
- at System.BitConverter.ToString(Byte[] value)
- at shex.shexx.hexfield_Dragrop(Object sender, DragEventArgs e)**
- StringBuilder b = new StringBuilder(bytes.Length * 3 - 1);
- int pos = 0;
- while (pos < bytes.Length - 1000) {
- b.Append(BitConverter.ToString(bytes, pos, 1000)).Append('-');
- pos += 1000;
- }
- b.Append(BitConverter.ToString(bytes, pos));
- hexfield.Text = b.ToString();
Add Comment
Please, Sign In to add comment