-----Original Message----- From: Jeffrey Richter (Independent Contractor) Sent: Thursday, May 09, 2002 3:49 PM To: Brian Grunkemeyer; Mahesh Prakriya Subject: RE: Re: [DOTNET] StringBuilder Overhead
For the record, what I say in the book is if a StringBuilder has ToString called on it AND THEN Length is set to 0, a new string is allocated by the StringBuilder. BRIAN: I am right about this, right? Mahesh, I'm not on the DOTNET discussion list but you can feel free to post this if you'd like. In fact, I'd appreciate it if you would post this response. Thanks, -- Jeffrey Richter http://www.Wintellect.com -----Original Message----- From: Brian Grunkemeyer Sent: Thursday, May 09, 2002 10:54 AM To: Mahesh Prakriya; Jeffrey Richter (Independent Contractor) Subject: RE: Re: [DOTNET] StringBuilder Overhead We don't allocate a new internal String in this case. At least not with our current implementation. We may end up rewriting StringBuilder more completely in managed code in Whidbey, but if we do it right probably still won't allocate a new String or char[] in this case. -----Original Message----- From: Mahesh Prakriya Sent: Thursday, May 09, 2002 9:48 AM To: Brian Grunkemeyer; Jeffrey Richter (Independent Contractor) Subject: FW: Re: [DOTNET] StringBuilder Overhead -----Original Message----- From: Jim Arnold [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 09, 2002 9:32 AM To: [EMAIL PROTECTED] Subject: Re: [DOTNET] StringBuilder Overhead I'll probably get into trouble here, but if Richter said that, I think he was mistaken. Setting Length = 0 is special-cased. It sets the StringBuilder's internal string's length to zero (via a sneaky assembly-protected method on String), but a new character buffer is not created. I haven't tested it against Remove(), but I suspect it might be quicker. Jim > -----Original Message----- > From: Jim Graf [mailto:[EMAIL PROTECTED]] > Sent: 09 May 2002 15:51 > To: [EMAIL PROTECTED] > Subject: Re: [DOTNET] StringBuilder Overhead > > > Thanks, Drew. > > I read that but wanted to confirm that that was the case. > > Jim > > >>> [EMAIL PROTECTED] 05/09/02 09:31AM >>> > Jim Graf [mailto:[EMAIL PROTECTED]] wrote: > > > Richter states that setting the length of a StringBuilder > > instance to 0 allocates a new character array. > > > > Does anyone know what the overhead of the following would be. > > > > StringBuilder sb(600,2000) > > ...use sb > > sb.Remove(0,sb.Length); > > > > I want to reuse the same Stringbuilder over and over again. > > From the SDK docs on StringBuilder::Remove: > > <snip> > The current method removes the specified range of characters from the > current instance. The characters at (startIndex + length) are moved to > startIndex, and the string value of the current instance is shortened > by length. The capacity is unaffected. > </snip> > > According to the last sentence, the character buffer will not be > affected. > > HTH, > Drew > > You can read messages from the DOTNET archive, unsubscribe from > DOTNET, or subscribe to other DevelopMentor lists at > http://discuss.develop.com. > > You can read messages from the DOTNET archive, unsubscribe from > DOTNET, or subscribe to other DevelopMentor lists at > http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.