streambuf performance 200x
Nathan Myers
ncm-nospam@cantrip.org
Thu Feb 13 19:23:00 GMT 2003
On Thu, Feb 13, 2003 at 11:11:13AM -0700, Martin Sebor wrote:
> Nathan Myers wrote:
> >It's time to talk about fixing core streambuf performance.
>
> Note that this is complicated by the requirements on strstreambuf.
> This program must still return 0 (it currently fails with a non-0
> exit status with libstdc++):
>
> #include <cstring>
> #include <strstream>
>
> int main ()
> {
> char buf[] = "abc";
> std::strstreambuf sb (buf, sizeof buf, buf);
> sb.freeze ();
> sb.sputc ('x');
> return std::strcmp (buf, "abc");
> }
By my reading, this constructs a strstreambuf with setg(buf, buf, buf)
and setp(buf, buf+4), and strmode == 0. (An attempt to read would
result in a call to underflow, which would return EOF.) The call to
freeze() has no effect, because it only operates on dynamic bufs.
The sputc() puts an 'x' at *buf, and the strcmp returns 1.
Where am I mistaken? Alternatively, what did you mean to say?
Nathan Myers
ncm@cantrip.org
More information about the Libstdc++
mailing list