Re: Preallocate ostringstream buffer
- From: "Bo Persson" <bop@xxxxxx>
- Date: Wed, 12 Apr 2006 16:46:14 +0200
"Jason Winnebeck" <gillius-ng2@xxxxxxxxxxxxxxxxxx> skrev i meddelandet
news:esu8rpiXGHA.1228@xxxxxxxxxxxxxxxxxxxxxxx
P.J. Plauger wrote:
And it's generally unnecessary with the library shipped with VC++
these days, since the buffer grows exponentially. Execution time
is not a problem. If space limitations are a problem, it's still
particularly easy to use strstream with a preallocated buffer.
I've always wondered about this problem with exponential growth. A
common technique here is to always increase by a power-of-2, so the
argument that the time spent reallocating in insignificant compared
to the task itself, but this can become an issue with space. I
suppose you mention that in your last sentence, but is there a
better way in the general case? Probably not. I suppose worst case
scenario is that your program takes twice the memory than it needs.
A common compromise here is to grow by a factor of 1.5 instead of 2.
This halves the theoretical worst case, without affecting runtime much
at all. It also reduces memory fragmentation a bit.
Bo Persson
.
- Follow-Ups:
- Re: Preallocate ostringstream buffer
- From: P.J. Plauger
- Re: Preallocate ostringstream buffer
- References:
- Preallocate ostringstream buffer
- From: Andrew Jarvis
- Re: Preallocate ostringstream buffer
- From: Tom Widmer [VC++ MVP]
- Re: Preallocate ostringstream buffer
- From: Jeff F
- Re: Preallocate ostringstream buffer
- From: P.J. Plauger
- Re: Preallocate ostringstream buffer
- From: Jason Winnebeck
- Preallocate ostringstream buffer
- Prev by Date: Re: Preallocate ostringstream buffer
- Next by Date: Release-mode only falure when comparing STL list::iterator-s
- Previous by thread: Re: Preallocate ostringstream buffer
- Next by thread: Re: Preallocate ostringstream buffer
- Index(es):
Relevant Pages
|