• Post Reply Bookmark Topic Watch Topic
  • New Topic

Implementation specific StringBuffer initialization/growth?  RSS feed

 
Kendra Barton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looking into performance improvements with StringBuffer initialization size, but need to assess risk/reward first. I can find lots of references that indicate the default size is 16 chars and size doubles (or doubles + 2) each time the length is exceeded. Is that for the SUN implementation only? Is it VM specific?

Any help is greatly appreciated.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kendra,

Welcome to JavaRanch!

Two things:

First, note that StringBuffer has a constructor which lets you specify the inital size, so a new version with a different default seems unjustified for that reason.

Second, regarding other growth strategies: there's a fairly straightforward argument that says that growing by a constant factor -- as ArrayList, Vector, and StringBuffer all do -- performs far better than growing by a fixed sized chunk.

Anyway, if you're interested in experimenting, I invite you to do so, but you shouldn't expect to find something radically better than what the existing classes already do.

As far as what applies to Sun's implementation vs. others: Sun's Javadoc says the initial size is 16 characters, so conforming implementations need to do the same. Neither the Javadoc nor the JLS mention the growth strategy, so that means it can vary by vendor and by release from a single vendor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!