Boost logo

Boost Users :

Subject: Re: [Boost-users] How to prevent boost serialize from object tracking apointer
From: Robert Ramey (ramey_at_[hidden])
Date: 2011-04-22 19:40:52

Frank wrote:
> Hi all,
> I have a shared_ptr to an object that changes (the underlying object
> is non-const, that is, not the shared_ptr), and I'd like to serialize
> the object each time it changes (size of the archive is not an
> issue). The problem stems, I think, from object tracking: every time
> after the first serialization, boost detects that the pointer is the
> same, and does not write out the (full, updated) object.
> I've tried putting in BOOST_CLASS_TRACKING(T,
> boost::serialization::track_never) but it won't compile because there
> is a BOOST_STATIC_ASSERT in shared_ptr.hpp that prevents setting
> class T's tracking to track_never if it is then serialized via a
> shared_ptr, with the comment that "correct shared_ptr serialization
> depends upon object tracking being used."
> Am I missing something obvious here,..?

It might be obvious now but it will be if you think about it. Suppose
you have one object pointed to by two different points. Now suppose
you don't track this pointer. When you load, you won't have a shared
pointer anymore. That is you'll have two objects instead of the orginal
And each "shared_ptr" won't be shared anymore. So after loading
things will be quite different than they were when you saved.

Robert Ramey

> Thanks,
> Frank

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