Here is what I did at the end. Since Nicol is right, and itβs really impractical, you must first turn off pointer tracking. Otherwise, you get false shared objects. Therefore, for starters, boot
BOOST_CLASS_TRACKING(yourDerivedClass,boost::serialization::track_never)
I also focused on simply registering objects that come from the same base object (for this you could just create an empty virtual database). Once this is done, it is important to make sure that it is considered as abstract (I definitely had virtual destructors and still added
BOOST_SERIALIZATION_ASSUME_ABSTRACT(yourBaseClass)
Register all derived classes with the archive after it is created (both for writing and reading)
arMsgs.template register_type<yourDerivedClass>();
Write only the final non-abstract class (if A is taken from B, comes from C, B is not registered). At least any registered class should disable tracking.
Finally add them to the archive as they become available.
To reload them, instead of using a special token for the end of the file, which will require verification, I went to
try { for(;;) { yourBaseClass obj; arObjs >> boost::serialization::make_nvp("Obj",obj); //your logic } } catch(boost::archive::archive_exception const& e) { }
It may be too much, so additional verification may be required, but it works for me. The advantage is that proper closure is not so important, for example. if your application crashes halfway, you can still process the last message you read.