Problem with StringBuffer

Wolfgang Muees wolfgang at
Sun Apr 2 12:09:32 PDT 2000

Am Sam, 01 Apr 2000 schrieb Tatu Saloranta:
> Wolfgang Muees wrote:
> > 
> > The right solution for this problem is IMO: don't reuse StringBuffer.
> > It is designed primary as an input buffer for a single string.
> I think I disagree here; at least if there's no other class for similar
> purpose. I am interested in optimizing Java-programs, and in general,
> one of the most efficient optimizations is to recycle objects. Object
> creation is not a cheap operation. Especially in this case, where
> StringBuffer does allocate a character array, it means there are at
> least 2 memory allocations and other initialization code. If the
> array truncation can be done when the array is being copied (during
> destringify() or whatever the method was), it won't add a new array
> allocation.
Tatu, I think you miss an important point here:

- most JAVA programmers try to code a program that behaves well
   under all JVMs available.
- The default StringBuffer implementation from SUN have problems
   with resuse of large Stringbuffers.

So, IMO all you can do is to code around this problem.

best regards

No Microsoft programs were used in the creation or distribution of this message.
If you are using a Microsoft program to view this message, be forewarned that I
am not responsible for any harm you may encounter as a result.

More information about the kaffe mailing list