-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 08 April 2004 15:24, Eric Blake wrote: > Tom Tromey wrote:
> I also wonder if the following implementation would be more efficient. > In the common case, StringBuffer/StringBuilder is used for appends, and > then converted to a String just before being discarded. Currently, for > every append, we adjust the underlying char[] and copy the appended > String into that array. Would it be better ... An alternate approach; some time ago I noticed that the ByteArrayOutputStream copied all data already present on each add, which is when we came up with the following approach that would be usefull here as well; Use a list of byte[] 's (or char[]'s) and optimistically allocate space in the first array. At appends copy all the bytes that will fit into the already allocated byte[], and allocate a second one for the rest. Use some algoritm that allocates based on previous size (say; 20% of current size) so you will get increasingly bigger arrays which you copy into. At the end you will have a list of arrays which you can copy into one big array on toString() or similar. We found that this is the most effecient way of accumulating data in one class with minimum garbage collection / allocations. Hope thats clear. - -- Thomas -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFAdVc1CojCW6H2z/QRAqsSAKDrtFYdfBLrpSmVgd20zR+uDOespgCgnhBz Q3bBChRLpbavbuKmP2lePdY= =x02e -----END PGP SIGNATURE----- _______________________________________________ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath