
Your solution below would likely work. These days I would expect find
the T* / size pair replaced with something like std::vector
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
void saveBuf(Archive & ar, const T * buf, size_t size) { bool isNull = (buf == 0); ar << size; ar << isNull; if (!isNull) ar.save_binary(buf, size * sizeof(T)); } template
void loadBuf(Archive & ar, T *& buf, size_t & size) { bool isNull; ar >> size; ar >> isNull; if (buf != 0) { delete buf; buf = 0; }
if(!isNull) { buf = new T[size]; ar.load_binary(buf, size * sizeof(T)); } else { buf = 0; } }
What do you thing about that? Any obvious problems? Are there perhaps already something like this in the library?
// Anders Sundman