Boost logo

Boost :

Subject: Re: [boost] [serialization] Must the objects being serialized outlive the archive?
From: Chris Yuen (kizzx2+boost_at_[hidden])
Date: 2010-09-18 13:44:45


Jeff Flinn wrote:

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

That was spot on! I did a couple of tests and I think I've confirmed this is
indeed the behavior and the reason why data gets corrupt. On my platform
(MSVC), new data gets allocated to the last free pointer's address and that
confuses boost::serialization.

>From your understanding, doesn't that basically means the "objects being
serialized must outlive the archive"? Since there's no way to tell "new" to
not allocate objects at an older address unless I keep objects there. So
basically I must keep all data in memory until the serialization process is
complete.

I tried to think hard about this. Do you see any workaround to this issue so
that I don't have to effectively double the memory usage? (Maybe have
boost::serialization write things out immediately and clear the internal
cached pointers)? Maybe boost::serialization should provide that command or
some kind of "flush" command?

Best regards,
Chris Yuen


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