静态成员和系列化提振 [英] static members and boost serialization
问题描述
我使用加速。序列化,以便存档类的内容。其中一个成员变量是一个静态的std ::向量。
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:
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & this->someVar;
ar & this->AnotherVar;
ar & staticVector;
}
然后肯定的是,静态矢量不会获取序列化每个实例。
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.
这篇关于静态成员和系列化提振的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!