Boost logo

Boost :

From: yahoo_at_[hidden]
Date: 2001-02-19 10:30:02


--- In boost_at_y..., "Craig Hicks" <hicks_at_k...> wrote:
> Hello,
>
> I recently started using containers to help in writing image
processing
> software which must
> be as fast as possible since it is used in a production line.
>
> I found to my dismay that std::vector always initialized all the
elements on
> resize().
> This turned out to be a big computation penalty. At least with
"new[]", no
> initialization
> is performed if the class/structure has no constructors, but this
appears
> not to be
> an option with std::vector. Likewise for destructors.
> Using push_back() would could a size check on each access, so is not
an good
> option.
> I wrote a template class (with an i/f which is a subset of
std::vector's)
> to get around this, but I wonder if I am missing something basic,
> if perhaps there is an easy (no more than say 1 line of code) to
make
> std::vector
> do the same thing?

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