"John Salmon" <> wrote in message
news:...
>>>>>> "PJ" == P J Plauger <> writes:
>
> PJ> "John Salmon" <> wrote in message
> PJ> news:...
>
>>> I'm working with two libraries, one written
>>> in old school C, that returns a very large
>>> chunk of data in the form of a C-style,
>>> NUL-terminated string.
>>>
>>> The other written in a more modern C++
>>> is a parser for the chunk of bytes returned by
>>> the first. It expects a reference to a
>>> std::istream as its argument.
>>>
>>> The chunk of data is very large.
>>> I'd like to feed the output of the first to
>>> the second WITHOUT MAKING AN EXTRA IN-MEMORY COPY.
>>>
>>> My attempts to create an istringstream from the
>>> chunk of data all seem to at least double the
>>> amount of VM used. Here's a short program demonstrating
>>> what I've tried. Is there any way to get "inside"
>>> the istringstream and tell it to use the 'chunk'
>>> directly, rather than insisting on making a copy?
>
> PJ> See the header <strstream>. It does exactly what you want,
> PJ> and it's part of the C++ Standard (albeit a bit old
> PJ> fashioned).
>
> Thanks to Usenet, I now have two workable solutions.
>
> Googling for strstream turns up lots of warnings that "strstream is
> deprecated", with dire warnings that it may be removed from future
> versions of the standard. OTOH, an istrstream does exactly what I
> want, without any extra custom machinery ( struct membuf : public
> streambuf ).
>
> Other than simplicity and possible compatibility with future
> standards, is there any reason to prefer one approach over the
> other?
You should prefer strstream because:
1) it's exactly what you need
2) it's still part of the C++ Standard
3) there's no reason to believe it'll become nonstandard anytime
soon, despite the dire warnings
4) even if it does officially go away, there's not a sane vendor
who'll stop supporting it for the next decade
So what the hell.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com