Reputation: 2504
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.
Upvotes: 2
Views: 369
Reputation: 2504
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.
Upvotes: 2
Reputation: 393739
The assumption you make is that Boost Serialization tracks instances on references. This is a false assumption.
AFAIR it tracks instances on pointers (and smart pointers).
Similar things apply to runtime dynamic types of polymorphic classes.
Upvotes: 0