This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::string::reserve vs std::vector::reserve


Joe Buck wrote:

>On Thu, Jun 16, 2005 at 12:41:58PM +0100, Jonathan Wakely wrote:
>  
>
>>So to summarise, the standard doesn't place any strict requirements on
>>the behaviour, so it is best not to assume anything more than
>>"capacity() will always be greater than or equal to size()" for strings.
>>    
>>
>It might be possible to assume a bit more.  The standard permits
>assignment to reduce the capacity, but the usual reason for doing
>reserve() is to speed up a subsequent sequence of append operations.
>  
>
Good point. On the other hand, the capacity may be rather larger than
the size not because of an explicit reserve, but because of the
"history" of the string, i.e., sequences of resize, erase, replace,
whatever, even simple grow according to the exponential grow policy.
Really, in principle many different strategies can make sense. Now
finally we have a new, rather clean (I hope) non-COW base class in
v7-branch that we can fine tune and tweak and put to test in every
possible way. As soon as I'm back from GCCSummit I will also add that
new stuff to mainline as an extension for easier availability.

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]