Re: Preallocate ostringstream buffer
- From: "P.J. Plauger" <pjp@xxxxxxxxxxxxxx>
- Date: Fri, 7 Apr 2006 00:19:28 -0400
"Jeff F" <not@xxxxxxxxxxxx> wrote in message
news:eR5h3RbWGHA.3492@xxxxxxxxxxxxxxxxxxxxxxx
Tom Widmer [VC++ MVP] wrote:
Andrew Jarvis wrote:
Dear All,
I want to write about 8Mb of data to a ostringstream and I do not
want the stream continually reallocating ever larger chunks of
memory as the data is written.
With ostrstream I can map the stream onto a preallocated buffer, eg.
char *buffer = new char[length];
ostrstream os(buffer, length);
Is a this possible with ostringstream?
No, sadly there is no ostringstream::reserve. Either use ostrstream
(assuming you don't need wide characters) or roll your own.
And the latter is particularly easy with the boost iostreams library, see:
http://www.boost.org/libs/iostreams/doc/index.html.
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.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
.
- Follow-Ups:
- Re: Preallocate ostringstream buffer
- From: Jason Winnebeck
- 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
- Preallocate ostringstream buffer
- Prev by Date: Re: Preallocate ostringstream buffer
- Next by Date: Re: Newbie: How to iterate map
- Previous by thread: Re: Preallocate ostringstream buffer
- Next by thread: Re: Preallocate ostringstream buffer
- Index(es):
Relevant Pages
|