views:

256

answers:

2

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

A: 

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.

Éric Malenfant
I try to serialize the whole vector<unsigned char> instead of each item. Now i get something like<data><item>1</item><item>2</item><item>170</item><item>255</item>....I need something like<data>0102AAFF</data>(notice the hexa encoding)I think that there has to be a solution in boost or at least some way to override the default behavior.
jab
A: 

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.

jab