Re: [Boost-users] Serialization of dynamic data

I have just noticed, shouldn't it be ~Dyn() { delete [] data; } -----Original Message----- From: Anders Sundman [mailto:anders.sundman@optonova.se] Sent: 01 February 2007 14:55 To: boost-users@lists.boost.org Subject: [Boost-users] Serialization of dynamic data 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 _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

You're right.. it should. Thanks! // Anders Sundman Pranckevicius, Tadas skrev:
I have just noticed, shouldn't it be
~Dyn() { delete [] data; }
-----Original Message----- From: Anders Sundman [mailto:anders.sundman@optonova.se] Sent: 01 February 2007 14:55 To: boost-users@lists.boost.org Subject: [Boost-users] Serialization of dynamic data
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
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Anders Sundman
-
Pranckevicius, Tadas