Boost logo

Boost :

From: Rainer Deyke (root_at_[hidden])
Date: 2002-02-25 13:03:08

----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, February 25, 2002 9:27 AM
Subject: Re: [boost] auto_sequence (was auto_vector)

> From: "Rainer Deyke" <root_at_[hidden]>
> > From: "Peter Dimov" <pdimov_at_[hidden]>
> > > What are the main differences between auto_vector<T> and vector<
> > > shared_ptr<T> > ?
> >
> > 'vector<shared_ptr<T> >' does not enforce strict ownership,
> Why is this a good thing? If I have a raw pointer and the
> dies, I'm left with a dangling pointer.

It is useful as a statement of intent. A strict ownership hierarchy
simplifies things. For instance, you never have to worry about
reference cycles.

> OTOH if I never hold pointers to objects when the container dies,
then a
> vector<shared_ptr<T>> will be equivalent to auto_vector.

You can't tell that this is the case without looking at all uses of
the container.

> > uses much
> > more memory, and is slightly slower on operations that copy the
> > underlying objects.
> Yes, the size/performance implications are, well, implied. :-) I was
> thinking about the semantics. I.e. is an auto_vector only an
> to be used when size/performance matters?

Size/performance always matters unless proven otherwise, especially in
library code. But there are several semantic differences, most of
them related to the fact that 'vector<shared_ptr<T> >::value_type' is
'shared_ptr<T>' while 'auto_vector<T>::value_type' is 'T *'.

Rainer Deyke | root_at_[hidden] |

Boost list run by bdawes at, gregod at, cpdaniel at, john at