Boost logo

Boost :

From: Theodore Papadopoulo (Theodore.Papadopoulo_at_[hidden])
Date: 2005-10-04 05:07:12


On Tue, 2005-10-04 at 09:23 +0200, Matthias Troyer wrote:
> On Oct 4, 2005, at 1:37 AM, Ian McCulloch wrote:
>

> >
> > You still have not stated what advantages such a container would
> > have over a
> > resizable container. In other words, if you omit the resize() et.
> > al. from
> > std::vector, what extra functionality can be gained in return?
>
> I see advantages in a variant of this idea, with a compile-time fixed
> capacity, an implementation of which was done a few years ago by
> Synge Todo and posted here. There the advantage is that pointer
> dereferencing can be avoided, and memory usage is minimized.

Another advantage is that you can store iterator to the array in other
structures without having a resize in parallel that invalidates all the
stored iterators. These are difficult to find bugs... Not that it is
impossible to use the current vector by getting the size right at
construction time, but the rule "never use resize" is difficult to
enforce.

Also bound checking might cost less as no operation is susceptible to
change the size of the container (and thus an intelligent compiler might
remove many checks).

And for multidimensionnal arrays, having bounds defined at compile time
can help optimization of array access (by generating optimal computation
of the array index).


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