I'm using Boost.Serialization to archive the contents of a class. One of the member variables is a static std::vector.
Archiving and restoring goes fine, but I was kind of hoping the library would save static members only once, it appears that, judging by the filesize, the static members are fully saved for each archived instance.
This is rather easily circumvented by using set/getters for the static vector and serializing the static vector outside the class once.
But I'd rather have a self contained class. Is there a clean and easy way to achieve archiving the static contents of a class only once?
Serialize the static vector before you serialize all of the class' instances.
If you serialize the vector like this:
Then sure, the static vector does get serialized with each instance.
Should you need any further clarification, post your
serialize
function and the function that invokes it, please.I have very limited experience with Boost.Serialization, so please consider what follows accordingly:
IIRC, the treatment you want for your static member is what is done with pointers. So maybe serializing a pointer to the static member would work.
Self-critique: I'm not sure how that could be applied when de-serializing, though.