std::string::reserve()

Paolo Carlini pcarlini@suse.de
Thu Feb 12 14:39:00 GMT 2004


Paolo Carlini wrote:

>> It does seem to me that previous versions of reserve() could return
>> with the string still in the leaked state, though, if the method
>> decided that no call to _M_clone() was necessary.
>
> Indeed, but in that case you didn't pay the price of _S_create inside
> _M_clone, so... probably a good trade-off: the string doesn't become
> sharable but we don't spend time copying it either...

Sorry for a little bit of confusion here: what I really mean is that,
probably, irrespective of the details of your change, we should remember
to _always_ call _M_set_sharable() before leaving reserve, since this
is allowed by the standard and by definition a sharable string can be
quickly refcopied.

Paolo.



More information about the Libstdc++ mailing list