Boost logo

Boost :

From: Peter Petrov (ppetrov_at_[hidden])
Date: 2004-11-18 08:19:24


Peter Dimov <pdimov <at> mmltd.net> writes:

>
> Peter Petrov wrote:
> > 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.
>
> The registry is not meant to outlive the deserialization process.

How can you define the lifetime of the deserialization process?

IIUC, the registry ought to live at least for as long as the archive from which
we deserialize. The archive, in turn, may well live during the entire lifetime
of the application (for example, if it is bound to a pipe).


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