ブースト シリアライゼーションを使用して、ビッグ オブジェクトの高速バイナリ シリアライゼーションに最適な設定を見つけようとしています。私のテストでは、bitwise serializable とタグ付けされた構造体の場合、個々のオブジェクトではなく、配列 (およびベクトル) でのみパフォーマンスが向上することが示されています。
たとえば、POD タイプのみで構成されたこの構造があるとします。
struct BigStruct
{
double m1;
long long m2;
float m3;
// ...
bool m499;
short m500;
};
namespace boost
{
namespace serialization
{
template <class Archive>
void serialize(Archive& ioArchive, BigStruct& ioStruct, const unsigned int iVersion)
{
ioArchive & ioStruct.m1;
ioArchive & ioStruct.m2;
ioArchive & ioStruct.m3;
// ...
ioArchive & ioStruct.m499;
ioArchive & ioStruct.m500;
}
}
}
#include <boost/serialization/is_bitwise_serializable.hpp>
BOOST_IS_BITWISE_SERIALIZABLE(BigStruct);
次に、単一のオブジェクトをシリアル化します
{
std::ofstream outStream(tmpFolder + "/BinarySerializationOfBigStruct.txt", std::ios_base::binary);
boost::archive::binary_oarchive binOutArchive(outStream, boost::archive::no_header);
BigStruct bigStruct;
std::clock_t c_start = std::clock();
binOutArchive << bigStruct;
std::clock_t c_end = std::clock();
// ...compute elapsed time...
}
1 つのオブジェクトの配列をシリアル化するよりも約 7 倍の時間がかかります
{
std::ofstream outStream(tmpFolder + "/BinarySerializationOfBigStructArray.txt", std::ios_base::binary);
boost::archive::binary_oarchive binOutArchive(outStream, boost::archive::no_header);
BigStruct bigStructArray[1];
std::clock_t c_start = std::clock();
binOutArchive << bigStructArray;
std::clock_t c_end = std::clock();
// ...compute elapsed time...
}
何か不足していますか?これは、ブーストのシリアライゼーションの見落としですか?
ところで、ブースト v1.53 を使用しています。