This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: streambuf performance 200x


Nathan Myers wrote:
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.
Hmm, you're right, according to the wording, the example should
fail. That seems rather strange, though, don't you think? My
(apparently misled) expectation was that freeze() would make
the buffer read only regardless of whether it was dynamic or
not.

Where am I mistaken?  Alternatively, what did you mean to say?
What I meant to say was that sputc() must not modify the buffer
unless it actually is modifiable. What caught my eye was the
statement

(this->pp != this->ep) ? (*this->pp++ = c) : this->overflow(c);

that would not guarantee that restriction unless freeze(true)
set pp to make (pp == ep) hold and the call to overflow() was
then made to fail, and freeze(false) restored the original
values of the pointers. But this approach relies on overflow()
having special knowledge of the state of the object, which
an overflow() overridden by a program cannot have. So my
impression is that sputc() cannot be made as simple as the
statement above.

Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]