[Bug libstdc++/52938] std::string::reserve request is not maintained if object is used in other object copy ctore
abdul.tohmaz at emc dot com
gcc-bugzilla@gcc.gnu.org
Wed Apr 11 20:32:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52938
--- Comment #2 from Abdul Tohmaz <abdul.tohmaz at emc dot com> 2012-04-11 20:32:26 UTC ---
(In reply to comment #1)
> Why do you think this is a bug? I don't see why x="aaa"; would not change the
> reserve.
>
> The main reason why it changes the reserve is that the backing part is shared
> between x and y.
I have called:
x.reserve(20);
which I expect that 20 bytes (at least) to be reserved to this string. So I
would expect no memory reallocation as long as my string can fit in my reserved
request.
Then I called x="aaa";
and then
x += "bbb";
Why do I see memory is being reallocated even though the string x content can
fit within what I requested in my reserve call?
More information about the Gcc-bugs
mailing list