[Bug libstdc++/20706] string::reserve severe performance regression

pcarlini at suse dot de gcc-bugzilla@gcc.gnu.org
Thu Mar 31 20:57:00 GMT 2005

------- Additional Comments From pcarlini at suse dot de  2005-03-31 20:56 -------
This is not a bug, it's the intended, standard conforming, behavior.

This is happening because, when you call dest.reserve(dest.length() + 1) the
string class is actually *shrinking* the capacity of the string, which at that
point, is *larger* than dest.length + 1. This implies slow reallocations.

In 3.4 (at variance with 3.3) we honor shrink requests, which happen when
reserve is passed an argument which is smaller than the current capacity. This
is very useful to spare memory, in some applications.

In order to fix the problem, make sure to always pass to reserve an argument
bigger than the current capacity.

*** This bug has been marked as a duplicate of 20114 ***

           What    |Removed                     |Added
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


More information about the Gcc-bugs mailing list