Boost logo

Boost :

Subject: Re: [boost] [serialization] Must the objects being serialized outlive the archive?
From: Stefan Strasser (strasser_at_[hidden])
Date: 2010-09-15 07:24:07


Zitat von Chris Yuen <kizzx2+boost_at_[hidden]>:

> Hi,
>
> I am using boost::serialization along with the eos::portable_archive (on
> Boost Vault). All the data that I serialize are polymorphic types, i.e.
> pointers. By experiment and days of frustration, I found out that the
> objects being serialized must "outlive" the archive or the serialization
> process -- otherwise I'd get segfault and corrupt data.
>
> I hope that was clear. To demonstrate this, I wrote a small example at
> http://boost.codepad.org/mqX5dUf6 (I'm a noob and I don't know the tradition
> to paste code -- should I just paste it in the message body or something?)
> The program will crash when you run it. However, if you comment out both the
> "delete" statements (leading to memory leaks, but at least the objects will
> outlive the archives), then everything works fine.

objects don`t necessarily have to outlive the destruction of the
archive, but you`re serializing multiple _tracked_ objects that - I
guess - have the same address because you "new" and "delete" them
consecutively.
read the chapter about "object tracking" in the boost.serialization
doc, and then if you really need to serialize "temporaries" make sure
that they`re not tracked.


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