I am assigning std::ostream *pout_ = output_.get();
where output_ is scoped_ptr<std::stringstream> output_;
after assigning i am filling *pout_ <<"large strings"; appx 1172528 characters.
But after some extent i am not able to insert charcters inside *pout_. I tried surfing on the net whats the maximum size of this class but couldn’t find.
Someone please tell how much characters maximum i can store in *pout_. Is there any function which can tell me the maximum size of this class??
There are several possible causes for output to an
ostreamto fail.The most obvious is that the underlying supporting media (memory, in the
case of an
std::ostringstream) is full. Another is that you’vereached some internal limit: a lot of systems have (or had) file size
limits which would hit you long before the disk was full, and some
systems have had similar constraints on single objects in memory (and
the
std::stringbufclass typically keeps its data in a single object).(There’s also the possiblity of a hardware error, but if this occurs
with
std::stringbuf, i.e. a memory error, the hardware probably won’tdetect it.)
All of these mean that there is no hard limit as to how much you can
write to a stream, string or otherwise. It all depends, and one time,
you might succeed writing 2 GB, and the next fail after 1 MB or less.
Practically speaking, in most cases, you should be aware of the fact
that writes can fail, test the results (after a final flush) and be
prepared to do something reasonable if they do.
In the specific case of string streams, of course, about the only
failure you’re likely to be able to detect is out of memory. (An
ostreamdoes not propagate an exception from thestreambuf; itsets the
badbitwhen one occurs, and if exceptions have been activatedfor
badbit, it will throw its own exception, not rethrow the originalone. Which means that an
std::bad_allocwill not propagate out.)A lot of applications don’t handle out of memory, and should logically
have set the new handler to abort. If you’ve set the new handler to
abort, then you can probably forego such error checking on string
outputs.