Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] Avoiding multiple de-serialization
From: Nat Goodspeed (nat_at_[hidden])
Date: 2014-03-11 10:54:39

On Mar 11, 2014, at 5:11 AM, beet <> wrote:

> I have a large, "directed" tree-like data structure (i.e., no cycles),
> holding boost::shared_ptr's either to container-objects or
> "leaf-objects".
> I'm storing
> boost::shared_ptr's to the leaf objects in a container outside of the
> tree. Getting access to the leaf objects would otherwise be very
> inefficient, as the tree can have virtually any geometry (except for
> cycles), and I do not know the geometry in advance.
> The tree is repeatedly (de-)serialized, and I would like to also
> (de-)serialize the top-level container, so I still have easy access to
> the leaf-objects after de-serialization.
> However, it is not clear to me what happens to the leaf-objects after
> de-serialization of both the tree and the external container.
> Will the leaf-objects be de-serialized twice ? Or might there be
> different leaf-objects in the external container and in the tree ?

The serialization library tries to save multiple pointers to the same object in such a way that deserializing them again produces pointers to the same object. I believe that functionality can be engaged for shared_ptrs, though I have not done that myself.

However - since deserializing necessarily requires a pass over the entire tree, why not just rebuild your leaf cache from scratch every time you read the underlying tree? What do you gain by serializing the leaf cache?

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at