Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-02-19 10:56:34


Bernard,

I think you missed the OP's point. Each push_back causes a check to make
sure the capacity() is at least enought to hold the new element.
However, you can eliminate most of this cost by using
  v.insert(v.end(), first, last);
where first and last are random access iterators.

-Dave
----- Original Message -----
From: <yahoo_at_[hidden]>

> From http://www.sgi.com/tech/stl/Vector.html
> void reserve(size_t)
> [4] Reserve() causes a reallocation manually. The main reason for
> using reserve() is efficiency: if you know the capacity to which your
> vector must eventually grow, then it is
> usually more efficient to allocate that memory all at once rather than
> relying on the automatic reallocation scheme. The other reason for
> using reserve() is so that you can control
> the invalidation of iterators. [5]
>
> then push_back() should be cheap...
>
> Cheers,
> Bernard
>
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk