Search code examples
c++serializationboostboost-serialization

Debug Boost.Serialization Address Tracking


Roughly speaking, I have an object o and a pointer to that object po = &o, which I serialize like this:

// Somewhere
ar & o;

// Somewhere else, but after somewhere
ar & po;

When serializing po, Boost.Serialization should discover that it has already serialized o and not serialize *po again. I have a situation where the library fails at discovering this situation and instead serializes o twice.

Unfortunately, all attempts at reproducing this behaviour in a simple example failed, and the original code is way too large to be posted here. So instead of a solution to the problem, I ask for a pointer to the relevant code section in Boost.Serialization which tracks the addresses and determines whether a pointer needs to be "deeply" serialized or not. I hope I can then do the debugging myself.

Of course, any best guesses about what the error might be are also welcome, but I don't want to strain your crystal balls too much. ;-)

Btw, I use boost::archive::text_oarchive if that is relevant.


Solution

  • The code section in question is the save_pointer() function in basic_oarchive.

    Boost.Serialization uses two characteristics to check whether an object has already been serialized: The object address and the object type. The address part is obvious, and if you think about also the type part makes sense. My problem was that I did not think about it and only checked that the two addresses in question are the same. This indeed held true, but since the types were different, the serialization library assumed it were two different objects.