On 23/03/2011 10:40, Mickael Wolff wrote:
> On 23/03/11 10:07, Tomalak Geret'kal wrote:
>> It's not necessarily strictly doubled.
>>
>> I don't see why you'd ever reserve *more* than the number
>> of records
>> possible from your query. What a pointless waste of space.
>> If anything,
>> you'd reserve *exactly* the number of records possible.
>
> You should learn C++ and common techniques before to comment
> what experienced developers do or say. For example,
> std::vector,std::string, reserve double space each time they
> exceed in capacity. That's a common optimisation in
> “contiguous” containers like std::string and std::vector
> (the goal is to lower the number of allocation then copy of
> handled objects).
>
> That's explained in Effective C++ from Meyers (Addison
> Wesley editions).
>
I am a C++ professional, and have been for many years. Your
rampant condescension is completely uncalled-for.
*You* should learn C++ before coming back with a response
like that.
The standard specifies only that, after a re-allocation,
.capacity() >= .size(). It says nothing about specifically
doubling capacity.
In ANSI ISO/IEC 14882:2003, see 21.3.3/11 for
std::basic_string, 23.2.4.2/2 for std::vector, and you can
look up the rest on your own time.
Tom