Re: Preallocate ostringstream buffer

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.

Jeff Flinn


.



Relevant Pages

  • Re: Preallocate ostringstream buffer
    ... I want to write about 8Mb of data to a ostringstream and I do not ... With ostrstream I can map the stream onto a preallocated buffer, ...
    (microsoft.public.vc.stl)
  • Preallocate ostringstream buffer
    ... 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 ... With ostrstream I can map the stream onto a preallocated buffer, ...
    (microsoft.public.vc.stl)
  • Re: Preallocate ostringstream buffer
    ... 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, ...
    (microsoft.public.vc.stl)
  • Re: ostrstream initial size.
    ... >>ostrstream has been deprecated. ... > There is no way to reserve space in an ostringstream. ... > indeed often a manual buffer is maintained. ... allows one to easily create a stream and streambuffer that uses a ...
    (microsoft.public.vc.stl)
  • Re: Calling external program in C++
    ... hack at overhauling some code I wrote _years_ ago that used an ... ostrstream, so it might benefit from some cleanup): ... ostringstream &) ...
    (comp.lang.cpp)