Boost logo

Boost :

Subject: [boost] [serialization] Must the objects being serialized outlive the archive?
From: Chris Yuen (kizzx2+boost_at_[hidden])
Date: 2010-09-14 22:38:36


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.

Is there a way so that I can "flush" the serialization process so that it
gets written immediately? The way that it is now, I must keep in memory all
the things that I want to serialize.

Thanks!
Chris Yuen


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