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

Paolo Carlini pcarlini@unitus.it
Wed Feb 12 13:07:00 GMT 2003


Pétur Runólfsson wrote:

>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).
>
Indeed. Your report is correct... just not easy to fix ;) !

>>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).
>
Yes, I agree with this statement of yours. In my opinion when appending 
single chars
with sputc the only standard conforming behaviour is calling overflow 
each time, even
if this has an high cost in terms of virtual function overhead.

>You might also want to look at DR 169.
>
Yes, I read it: the only part of my patch for 9404 which is already in 
the final form, is
some addittional documentation inside overflow about DR 169 ;)

Paolo.



More information about the Libstdc++ mailing list