Click here to Skip to main content
15,911,786 members
Home / Discussions / C#
   

C#

 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 13:26
sitebuilderLuc Pattyn8-Jun-10 13:26 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 13:59
protectorAspDotNetDev8-Jun-10 13:59 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 14:06
sitebuilderLuc Pattyn8-Jun-10 14:06 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 14:16
protectorAspDotNetDev8-Jun-10 14:16 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 14:28
sitebuilderLuc Pattyn8-Jun-10 14:28 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 12:24
mveDave Kreskowiak8-Jun-10 12:24 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 12:57
protectorAspDotNetDev8-Jun-10 12:57 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak8-Jun-10 17:21
mveDave Kreskowiak8-Jun-10 17:21 
aspdotnetdev wrote:
My guess is that Win32 uses a structure similar to a StringBuilder


Kind of. In Win32, all a string really is is a coniguous block of memory storing the bytes of the characters. When the Text property is set, all it's doing is sending a pointer to the new string to the Win32 window. If you use AppendText, it uses Win32 messages to tell the window what text to select and what to replace it with. Win32 will allocate a new block of memory and do the appropriate copy operations to insert the new text into the string in the new memory location, then free the original string.


aspdotnetdev wrote:
You said there was nothing funky going on,


There isn't. Not to me anyway. It's just backed by an unmanaged field in the window properties. The Text property you get in return is exactly the same as if you sent a WM_GETTEXT message to the TextBox window handle and processed the pointer it sends back.


StringBuilder just keeps an array of characters and exposes methods to manipulate that array. Arrays in .NET are immutable. If it needs to expand that array, it has to create a new one of the needed size, copy the data over, then free the original array.

Under Win32 (or C), that memory block can be expanded in place if there is space available for it. If not, realloc (of other variant) will automatically allocate a new block copy the data over and free the original block of memory. In either case, a pointer is returned to the expanded block of memory, whether it moved or not. StringBuilder doesn't have the option of not moving the data.


aspdotnetdev wrote:
There are calls to other functions that probably manage things more intelligently than you seem to think append operations are handled.


No, I know how they're handled, I read the code and did the research on what the SendMessage calls were doing. A background in Win32 also helps tremendously.

A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008
But no longer in 2009...




GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 17:34
protectorAspDotNetDev8-Jun-10 17:34 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak9-Jun-10 2:03
mveDave Kreskowiak9-Jun-10 2:03 
GeneralRe: making a text box more efficient Pin
AspDotNetDev9-Jun-10 5:39
protectorAspDotNetDev9-Jun-10 5:39 
GeneralRe: making a text box more efficient Pin
LookSharp8-Jun-10 17:24
LookSharp8-Jun-10 17:24 
GeneralRe: making a text box more efficient Pin
Dave Kreskowiak9-Jun-10 2:01
mveDave Kreskowiak9-Jun-10 2:01 
GeneralRe: making a text box more efficient Pin
LookSharp9-Jun-10 3:19
LookSharp9-Jun-10 3:19 
AnswerRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 6:57
sitebuilderLuc Pattyn8-Jun-10 6:57 
GeneralRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 9:22
protectorAspDotNetDev8-Jun-10 9:22 
GeneralRe: making a text box more efficient Pin
Luc Pattyn8-Jun-10 9:30
sitebuilderLuc Pattyn8-Jun-10 9:30 
AnswerRe: making a text box more efficient Pin
AspDotNetDev8-Jun-10 9:18
protectorAspDotNetDev8-Jun-10 9:18 
Questiongridview pagination Pin
FEMDEV8-Jun-10 5:35
FEMDEV8-Jun-10 5:35 
AnswerRe: gridview pagination Pin
Dave Kreskowiak8-Jun-10 6:18
mveDave Kreskowiak8-Jun-10 6:18 
Questionhow to convert whole .hex file to bin file Pin
bhavin chheda8-Jun-10 5:22
bhavin chheda8-Jun-10 5:22 
AnswerRe: how to convert whole .hex file to bin file Pin
loyal ginger8-Jun-10 5:36
loyal ginger8-Jun-10 5:36 
AnswerRe: how to convert whole .hex file to bin file Pin
OriginalGriff8-Jun-10 6:29
mveOriginalGriff8-Jun-10 6:29 
AnswerRe: how to convert whole .hex file to bin file Pin
harold aptroot8-Jun-10 6:31
harold aptroot8-Jun-10 6:31 
Questionvideo subtitles Pin
Myn928-Jun-10 5:05
Myn928-Jun-10 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.