About std::vector::resize().
Martin Sebor
sebor@roguewave.com
Wed May 26 14:08:00 GMT 2004
Carlo Wood wrote:
> On Tue, May 25, 2004 at 01:05:04PM -0600, Martin Sebor wrote:
>
>>Theodore Papadopoulo wrote:
>>The code below must not abort for any (n > 0) but if resize()
>>constructed a new vector and swapped *this for it, it would.
>>
>> std::vector<T> v;
>> v.resize (1);
>> v.reserve (n);
>> T *p = &v [0];
>> v.resize (n); // must not reallocate
>
>
> Because the (reserved) "size" is already n there is no need
> for reallocation - so the mentioned algorithm will not
> be used.
Ah. Sorry for the misunderstanding.
FYI, the "reserved size" of a vector is known as its capacity :)
Martin
More information about the Libstdc++
mailing list