libstdc++/4150: catastrophic performance decrease in C++ code
Thu Apr 18 06:12:00 GMT 2002
On Thu, Apr 18, 2002 at 02:24:01AM +0000, Nathan Myers wrote:
> > ... how often do people
> > really read a few characters, write a few characters, and then read a few
> > more characters without an intervening seek?
> > A problem with the current implementation of this is that if we do a read
> > on an input/output filebuf, we end up writing the contents of the buffer
> > back out to the file, even if we've never requested a write. Oops.
> Not only that, it's undefined behavior to switch between reading
> and writing without a seek between. We don't have to make it do
> anything "reasonable" in that case, but might just as well set
> badbit if that were convenient, as a favor to users who might not
> otherwise have known they were corrupting their stream state.
I noted this problem a few years ago, at which point I implemented my own
streambuf class. I don't think it will be useable for libstdc++ ;), but
it might be instructive/interesting to have a look at my design(?).
You can find documentation about it in paragraph 2.2 of
please note figure 2 especially (explanation is in the text above that).
The whole page of that URL is about my solution for this problem.
Unfortunately, it would mean changing the standard rather drastically
so this probably just stays a seperate library.
Carlo Wood <email@example.com>
More information about the Libstdc++