Optimal basic_string<>::append

Paolo Carlini pcarlini@unitus.it
Tue Dec 18 00:32:00 GMT 2001


Ryszard Kabatek wrote:

> Paolo Carlini wrote:
> >
> > Well, on third thought (hopefully the final one on my part :-) I believe
> > that your approach, while safe, would not gain us much. That's why: the
> > reserve call that you spare, either reallocates the string to the required
> > capacity or not. In the second case it does'nt cost much. In the first
> > case, the new reallocated string is un-shared and with the required
> > capacity. As such, inside _M_mutate it is *not* reallocated (see the if at
> > the beginning of _M_mutate). So...
>
> Reserve allocates exact the required storage amount. Just try to append
> 1000000 one character strings to an empty string and you will see how
> "good" is the current implementation. I sent a benchmark some months ago,
> http://gcc.gnu.org/ml/libstdc++/2001-07/msg00030.html
> and a patch
> http://gcc.gnu.org/ml/libstdc++/2001-07/msg00170.html

Ryszard, you are not following the discussions on libstdc++.
The problem you mention is *completely* solved right now as part of more general
development work affecting basic_string. See:
http://gcc.gnu.org/ml/libstdc++/2001-12/msg00144.html

Cheers,
Paolo.



More information about the Libstdc++ mailing list