Boost logo

Boost :

From: Peter Petrov (ppetrov_at_[hidden])
Date: 2004-11-18 04:27:14


Gennadiy Rozental <gennadiy.rozental <at> thomson.com> writes:

> Here we do very simple (or complex,depends on point of view) trick instead
> of above
> Let say we have somewhere map<T*,shared_ptr<T>*> registry;
>
> if( registry[raw_ptr] == 0 ) {
> t = shared_ptr<T>( raw_ptr )
> registry.add( raw_ptr, &t );
> }
> else
> t = *registry[raw_ptr];
>
> > // current shared_ptr implementation depends upon an internal pointer
> to
> > a shared count.
> > }
>
> Do I miss something important?

What happens when some time after deserialization, one of the deserialized
shared_ptr's is destroyed? Your "registry" has no way to know that and will
still hold a shared_ptr referencing the same object, which is not correct.


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