Question

I have to serialize an object that contains a std::vector that can contain thousand of members, with that vector sizes the serialization doesn't scale well.

According with the documentation, Boost provides a wrapper class array that wraps the vector for optimizations but it generates the same xml output. Diving in boost code, i've found a class named use_array_optimization that seems to control the optimization but is somehow deactivated by default. i've also tried to override the serialize function with no results.

I would like to know how to activate that optimizations since the documents at boost are unclear.

Thank you in advance

Was it helpful?

Solution 2

Finally, I used the BOOST_SERIALIZATION_SPLIT_MEMBER() macro and coded two functions for loading and saving. The Save function looks like:

template<class Archive>
void save(Archive & ar, const unsigned int version) const
{
    using boost::serialization::make_nvp;
std::string     sdata;
Vector2String(vData, sdata);
ar & boost::serialization::make_nvp("vData", sdata);
}

The Vector2String function simply takes the data in vector and format it to a std::string. The load function uses a function that reverses the encoding.

OTHER TIPS

The idea behind the array optimization is that, for arrays of types that can be archived by simply "dumping" their representation as-is to the archive, "dumping" the whole array at once is faster than "dumping" one element after the other.

I understand from your question that you are using the xml archive. The array optimization does not apply in that case because the serialization of the elements implies a transformation anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top