
Ok, my bad. I've found the docs:
http://www.boost.org/libs/serialization/doc/serialization.html#splitting
But the general question remains, what to do with dynamic data?
It's often the case that I find a T* and a size in classes. I've been
thinking about introducing some kind of convenience functions for this.
Perhaps something along these lines:
template
Hi!
About the boost::serialization library, what is the best way to handle dynamic data in classes? Any idéas, suggestions or caveats? I didn't manage to find anything about this in the docs.
Consider the following sample class:
struct Dyn { Dyn(int s) : data(0), size(s) { data = new char[size]; }
~Dyn() { delete data; }
char* data; int size;
private: friend class boost::serialization::access; template< class Archive > void serialize( Archive &ar, unsigned int ver ) { // -> ar & data; What to do here? ar & size; } };
What to do with the data pointer?
Is there any way to determine (in the serialize function) if a serialization or "de-serialization" is taking place? And have different behaviours - either allocating a new char[x] or copying data to the archive?
Is there any way to store dynamic data in an archive?
Best regards, Anders Sundman