c++optimizationboost-serialization

How to use array optimization in boost serialization


I have to serialize an object that contains a std::vector<unsigned char> 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.


Solution

  • 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.