
Peter Dimov wrote:
Correct deserialization of shared_ptr/weak_ptr requires keeping a container of shared_ptr<void> that holds the objects alive during the deserialization process.
Indeed.
The problem I've not been able to solve so far is where to keep it without making shared_ptr special WRT the archives. :-)
At work, we're using a modified version of boost::serialization where we've added a shared_ptr registry (the container to keep the pointed- to objects alive) as a kind of user data to the archives. So this could be a way, which would, however, require users to explicitly associate the shared_ptr registry with archives that have to deserialize shared_ptrs/weak_ptrs. We haven't found this to be much of a problem, though. In general, I propose adding some sort of user data mechanism to archives. Our system is quite complex and we use boost::serialization exclusively to serialize all the classes. Sometimes it is necessary to store certain state during serialization/deserialization that is associated with archives and that can be accessed from within serialization code. This is especially true for objects that depend on each other and have more complex relationships, such as shared_ptr and weak_ptr. Best Regards, Martin TAB Austria Haiderstraße 40 4052 Ansfelden Austria Phone: +43 7229 78040-218 Fax: +43 7229 78040-209 E-mail: martin.ecker@tab.at http://www.tab.at