About the author
Who's the genius who wrote TextBox.AppendText?
TextBox is supposed to support up to 2GB or 4GB of text, depending on whether it's a single line or multi line textbox.
Yet, due to an oversight by the person who wrote AppendText, TextBox can only support only up to a total of 32767 characters, when AppendText is used.
The code for AppendText looks like this (from Reflector)
In the block of code after IsHandleCreated, a EM_LIMITTEXT is sent to the underlying control to 32767 characters. Then, a EM_REPLACESEL is sent, to add the new text, followed by a EM_SETMODIFY, then a EM_LIMITTEXT again.
If you'd like to try, drop a TextBox and a Button onto a Winform, change the TextBox's Multiline property to true, make sure that MaxLength reads, say, 50000, and add code that reads
var I: Integer;begin for I := 1 to 32767 do TextBox1.AppendText(Convert.ToString(I)+Environment.NewLine);end;
to the Button's Click event. Run the form, and click the button. You'll see that the maximum number that the TextBox shows is about 5644. If, at this point, you try to read TextLength, you'll see that it is exactly 32767 characters.
So, Microsoft, what's the point of giving your candidates IQ tests if the testers and programmers can't even write and test code properly?
A method to design records so that they're allocated on a specific byte boundary, such as 16 bytes, 512 bytes, 4096 bytes, etc.