我使用Boost.Serialization來序列化一個std :: map。代碼看起來像這樣Boost.Serialization在不同平臺上的序列化程度不同嗎?
void Dictionary::serialize(std::string & buffer)
{
try {
std::stringstream ss;
boost::archive::binary_oarchive archive(ss);
archive << dict_;
buffer = ss.str();
} catch (const std::exception & ex) {
throw DictionaryException(ex.what());
}
}
void Dictionary::deserialize(const char * const data, int length)
{
try {
namespace io = boost::iostreams;
io::array_source source(data, length);
io::stream<io::array_source> in(source);
boost::archive::binary_iarchive archive(in);
archive >> dict_;
} catch (const std::exception & ex) {
throw DictionaryException(ex.what());
}
}
我在Mac Snow Leopard和Ubuntu Lucid 10.04上編譯並測試了代碼。兩個系統都有Boost 1.40。在Mac上,我自己構建了代碼。在Ubuntu上,我通過aptitude獲得了二進制文件。
問題:當我在Mac上序列化地圖時,我無法在Ubuntu盒上反序列化它。我得到無效簽名例外,如果我嘗試。
請注意,這可能會對應用程序的性能產生非常顯着的影響。 – 2011-10-24 14:56:09