[RFC] libstdc++/9404 or weird stringbuf internals

Pétur Runólfsson peturr02@ru.is
Wed Feb 12 13:00:00 GMT 2003


Hi

> But, if someone (Pétur ;) wants to see overflow called during
> a sputc which starts with pptr() == epptr()...

overflow must be called if a class derived from stringbuf is
supposed to work correctly. Google returns a number of posts
from people who have tried to derive from the standard stream
buffers (including stringbuf).

> What to do, then?
> 
> I could try changing both _M_out_buf_size() and overflow
> to the effect of calling overflow for each sputc of a sequence.
> This has a price, however, in terms of virtual functions called.

If efficiency is a concern, sputn should be used instead of
sputc. For maximal efficiency, stringbuf shouldn't be used at all
(for example str() is an O(N) operation).

> Is this the only standard-conforming possibility?
> 
> Perhaps I misread the standard and it is not really compulsory
> to call overflow whenever pptr() == epptr()?
> 
> Please help!

You might also want to look at DR 169.

Petur



More information about the Libstdc++ mailing list