Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2004-11-18 01:49:25


> > I still believe We dont need any modification in shared_ptr to make it
> > serializable (even more I believe it's evil od request one). I don't
> > remember ever your answer on my last post.
>
> evil to REQUEST a modification - wow. Don't even look at the hack I had
to
> do - I might get the death penalty!

Byevil I meant that I do not see any need for shared_ptr counters direct
acces neither for serialization nor for deserialization and the fact that
you request it seems suspicious.

> I thought about a little more. If I rememeber correctly the essense of
the
> problem during de-serialization was:
>
> template<class Archive, class T>
> void serialize(Archive &ar, shared_ptr<T> & t){
> T * raw_ptr;
> ar >> raw_ptr;
> t = shared_ptr(raw_ptr); // problem is here - not matched with other
> shared pointers that might point to raw_ptr

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?

Gennadiy


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