[Mono-devel-list] StringBuilder patch

Ben Maurer bmaurer at users.sourceforge.net
Tue Jan 13 16:32:21 EST 2004


On Tue, 2004-01-13 at 11:47, Paolo Molaro wrote:
> On 01/12/04 Ben Maurer wrote:
> > One other thing we should do is to preserve the old source. The old
> > stringbuilder is actually VERY useful, and highly performant as a
> > `string buffer'. For example, if you allocate one static stringbuilder,
> > and use it multiple times, the cost of the extra slack on the end of
> > strings is more than what is lost by having the extra char [] buffer.
> [...]
> > In this case, it is MUCH more efficient to do it the old way (assuming
> > you have a pretty big number of strings.
> > 
> > So, it would be nice if we could publish the old source as a utility
> > class. We should rename it something like Mono.StringBuffer.
> 
> The new code already creates a new string if the string buffer is unused
> for the most part. Maybe the code can be changed in the future to use
> some different criteria, like, don't waste more than x bytes etc.
> I don't see any reason to keep the old code around: it's much more a
> waste to keep it maintained and have two copies of mostly the same code
> jitted in the same application.

The real issue is when you create long lasting strings. Lets say you
create 10 k strings each with a length of 17 bytes. If the buffer is 32
bytes, you end up wasting 150 kb.

In the MCS tokenizer, for large programs such as corlib, we could end up
taking a megabyte or more extra memory and holding it.




More information about the Mono-devel-list mailing list