#include #include #include #include struct Base { Base() : base(42) { } virtual ~Base() { } int base; template void serialize(Archive & ar, const unsigned int version) { ar & base; } }; struct Derived : Base { Derived() { } Derived(int n) : size(n) { while(--n > 0) derived[n] = n; } int size; int derived[0]; template void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::base_object(*this); ar & size; for(int i = 0; i < size; ++i) ar & derived[i]; } }; BOOST_CLASS_EXPORT_GUID(Derived, "Derived") int main() { std::ofstream ofs("filename"); Base *x = new(new unsigned char[sizeof(Derived) + 42 * sizeof(int)]) Derived(42); { boost::archive::text_oarchive oa(ofs); oa << x; } x->~Base(); delete[] reinterpret_cast(x); // obviously this will fail Base *y; { std::ifstream ifs("filename"); boost::archive::text_iarchive ia(ifs); // any possibility to specify the amount of memory needed to create y? // unfortunatly i have found none ia >> y; } return 0; }