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: About std::vector::resize().


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


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