Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-05-20 08:13:13

Jeff Flinn wrote:
> It appears to me that the shared_ptr<T>::px is not even structurally
> required, but is an optimization trading space to avoid an extra
> pointer dereference to the sp_counted_base_impl<P,D>::P member. Or
> have I missed something with my limited exposure?

Consider this example:

struct A { int a; };
struct B: public A { int b; };
struct C: public A { int c; };
struct D: public B, public C {};

shared_ptr<D> p1( new D );
shared_ptr<B> p2( p1 );
shared_ptr<C> p3( p1 );

shared_ptr<A> p4( p2 );
shared_ptr<A> p5( p3 );

Now p4 and p5 are both of type shared_ptr<A>, both point to an object with a
dynamic type D, but p4.get() != p5.get(). The only difference is in px.
(This is an answer to the general shared_ptr question. It's reasonable to
disallow serialization in this particular scenario.)

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