Boost logo

Boost :

From: Rainer Deyke (root_at_[hidden])
Date: 2002-02-05 18:49:42


----- Original Message -----
From: "Howard Hinnant" <hinnant_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, February 05, 2002 12:59 PM
Subject: Re: [boost] auto_vector - vector with auto_ptr semantics

> On Tuesday, February 5, 2002, at 02:31 PM, Rainer Deyke wrote:
>
> > There are three ways of dealing with this specific problem:
> >
> > 1. If any exceptions are thrown by the copy operation, catch it,
move
> > all elements back into their original position, and rethrow.
> >
> > 2. Copy 'x' first, then move the elements, then move the copy of
'x'
> > into place.
> >
> > 3. push_back 'x' and use 'std::swap' to fix the order of the
vector
> > elements. This requires no move operation.
>
> Yes, these will all work. And they are all less efficient than
moving
> elements out of the way once (directly to where they belong),
leaving
> valid elements in their place and copying x directly into place.

While this is technically true, they are also all potentially orders
of magnitude faster than the naive copying approach. They are close
enough to optimal that I am not sure if further optimization is worth
it.

> Why should we create a sub-optimal design? vector is to C++ like
malloc
> is to C. Everybody and their dog uses it to death. vector must be
rock
> solid and as efficient as possible in code size, performance, and
memory
> usage.

'malloc' is also technically sub-optimal. That doesn't prevent
everybody and their dog from using it to death.

--
Rainer Deyke | root_at_[hidden] | http://rainerdeyke.com

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