Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Re: StringBuilder Date: Sat, 17 Sep 2011 15:34:19 -0700 Organization: Canadian Mind Products Lines: 28 Message-ID: References: <96f358c8-a024-40db-b60b-300186c2f813@o10g2000vby.googlegroups.com> Reply-To: Roedy Green NNTP-Posting-Host: RCd/Ul4tyxGUBII8WGwa5g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 6.00/32.1186 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8110 On Sat, 17 Sep 2011 19:56:50 +0300, Stanimir Stamenkov wrote, quoted or indirectly quoted someone who said : >The StringBuilder.toString() is really fast - that's the point, and >I don't think it is worth mentioning it. The places where StringBuilder wastes CPU cycles is when you have a bad estimate and it has to create new buffer and copy what it has done so far to it. If estimate is two low, you can get repeated such doublings. If it is too high, you fill up RAM too quickly and force premature c. My solution was FastCat which is quite easy to get a bang on estimate. see http://mindprod.com/products1.html#FASTCAT StringBuilder composes its string in a char[]. Unfortunately it can't simply plop that into a String object at the end. It has to allocate yet another buffer, copy into it, and that becomes your string object. The JVM is worried there might be encumbrances (pointers to) the char[]. So it has to copy rather than reference. Perhaps a little native code could bypass the final copy. -- Roedy Green Canadian Mind Products http://mindprod.com Your top priority should be fixing bugs. If you carry on development, you are just creating more places you will have to search for them.