C++ Serialization

From Schmid.wiki
Jump to: navigation, search

Using Boost Serialization

Example code:

// ...
boost::archive::text_oarchive oa(std::cout);
Serializable serializable;
oa << serializable;

When using boost::archive::text_oarchive, I have had trouble with this compile error:

/PATH/boost/archive/detail/oserializer.hpp:564: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>' 

Apparently, this can be fixed by only serializing const instances or references:

// ...
boost::archive::text_oarchive oa(std::cout);
Serializable serializable;
const Serializable &s = serializable;
oa << s;

In a simple test, binary_archives were about 20 times faster than text_archives.

Personal tools