How to prevent boost serialize from object tracking a pointer

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, or is another a way to accomplish this? Any help would be greatly appreciated... Thanks, Frank -- View this message in context: http://boost.2283326.n4.nabble.com/How-to-prevent-boost-serialize-from-objec... Sent from the Boost - Users mailing list archive at Nabble.com.

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 one. 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

Hi Robert, Thanks for the quick reply (and all your hard work on the library...). I understand what you are saying, that makes a lot of sense. I don't see any other way to ensure the integrity of the shared_ptr than to forbid track_never. However, it still seems strange that when I serialize the shared_ptr the second time (after the pointed-to object has been changed), what is serialized does not reflect any change. It's almost like it would be safer to forbid serialization of shared_ptr to non-const objects, altogether... Anyway, thank you for the explanation, it is much appreciated. Frank -- View this message in context: http://boost.2283326.n4.nabble.com/How-to-prevent-boost-serialize-from-objec... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
Frank
-
Robert Ramey