Boost logo

Boost :

Subject: Re: [boost] [serialization] Must the objects being serialized outlive the archive?
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2010-09-17 08:03:37


Chris Yuen wrote:
> Robert,
>
>
>> It is a fundamental concept that saving data to an archive should
>> not alter the data. In many cases this is detected at compile time
>> and a warning is issued. As noted in another post, you might
>> snooker the system by suppressing tracking,
>
> I don't really understand. Why does the tracking has something to do with
> the object's lifetime? Doesn't boost::serialization has all the information
> it needs (tracking info, data, etc.) when I call "oa << base_ptr"? Isn't it
> possible to just write out everything to the stream?

IIUC, tracked objects have their addresses place in a map, so that
subsequent serialized pointers of the same value are serialized as a
reference to the original object at that address, rather than
serializing another copy of the object. Your code makes it possible for
base_ptr to have the same value on subsequent calls to
Serializer::serialize, but for different types. Could be that seeing to
different types with the same address is confusing things. I could be
that if you only serialized Strings or Doubles, that you would not "seg
fault", but you'd only see N of the first object serialized.

HTH, Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk