> Hello folks, i have a problem with StringBuffer, profiling my > web-application i noticed, StringBuffer due to its creation and use consumes > too much memory. Does onyone here know a good way to solve that problem?
Not much to go on there, but a key factor to using StringBuffer "well" is if you can estimate how big the resulting String will be beforehand. This is because StringBuffer starts out rather small (16 characters as I recall) and grows as needed. Each time it grows, it has to allocate a new buffer and copy the previous buffer, so it can be wasteful if misused this way. So, if you know before, do something like: StringBuffer buf = new StringBuffer(4000); Or, if you already have a buffer and you need to add another 500 characters, you can use: buf.ensureCapacity(buf.length()+500); The second will ensure that the buffer is at least big enough to hold its current contents plus another 500 characters so that if it's not big enough, it will only do one reallocation as you add up to another 500 characters. Good luck, David --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]