[Serialization] Avoiding multiple de-serialization
Dear Boost-Community, 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.e. individual objects not holding other objects. All shared_ptr's hold base-pointers, i.e. the leaf-objects share a common base type, but not much else. I would now like to collect statistics on some of the leaf-objects during the program run. In order to do this, 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 ? Thanks for any insight you may provide. Best Regards, beet
On Mar 11, 2014, at 5:11 AM, beet
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?
participants (2)
-
beet
-
Nat Goodspeed