From ddcefaf15d43fa7e252a52bf875e94b47a6e440b Mon Sep 17 00:00:00 2001 From: Shane Grant Date: Mon, 17 Jun 2013 11:50:41 -0700 Subject: [PATCH] Specialized save/load for vectors with default allocator --- binary_archive/vector.hpp | 33 +++++++++++++++++++++++++++++---- performance.cpp | 4 ++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/binary_archive/vector.hpp b/binary_archive/vector.hpp index 762f5106..014e7171 100644 --- a/binary_archive/vector.hpp +++ b/binary_archive/vector.hpp @@ -6,9 +6,33 @@ namespace cereal { - //! Serialization for std::vectors of arithmetic (but not bool) types to binary + //! Serialization for std::vectors of arithmetic (but not bool) types to binary, default allocator template inline - typename std::enable_if::value && !std::is_same::value, void>::type + typename std::enable_if::value && !std::is_same::value + && std::is_same>::value, void>::type + save( BinaryOutputArchive & ar, std::vector const & vector ) + { + ar & vector.size(); // number of elements + ar.save_binary( vector.data(), vector.size() * sizeof(T) ); // actual data + } + + //! Serialization for std::vectors of arithmetic (but not bool) types to binary, default allocator + template inline + typename std::enable_if::value && !std::is_same::value + && std::is_same>::value, void>::type + load( BinaryInputArchive & ar, std::vector & vector ) + { + size_t vectorSize; + ar & vectorSize; + + vector.resize( vectorSize ); + ar.load_binary( vector.data(), vectorSize * sizeof(T)); + } + + //! Serialization for std::vectors of arithmetic (but not bool) types to binary, special allocator + template inline + typename std::enable_if::value && !std::is_same::value + && !std::is_same>::value, void>::type save( BinaryOutputArchive & ar, std::vector const & vector ) { size_t const dataSize = std::addressof(vector.back()) - std::addressof(vector.front()) + 1; @@ -18,9 +42,10 @@ namespace cereal ar.save_binary( vector.data(), dataSize * sizeof(T) ); // actual data } - //! Serialization for std::vectors of arithmetic (but not bool) types to binary + //! Serialization for std::vectors of arithmetic (but not bool) types to binary, special allocator template inline - typename std::enable_if::value && !std::is_same::value, void>::type + typename std::enable_if::value && !std::is_same::value + && !std::is_same>::value, void>::type load( BinaryInputArchive & ar, std::vector & vector ) { size_t vectorSize; diff --git a/performance.cpp b/performance.cpp index e503a053..20eb0f8d 100644 --- a/performance.cpp +++ b/performance.cpp @@ -307,7 +307,7 @@ int main() test( name.str(), data ); }; - //vectorCharTest(1024*1024*1024, randomize); // 1 GB + vectorCharTest(1024*1024*1024, randomize); // 1 GB //######################################## auto vectorPoDStructTest = [&](size_t s) @@ -323,7 +323,7 @@ int main() vectorPoDStructTest(64); vectorPoDStructTest(1024); vectorPoDStructTest(1024*1024); - //vectorPoDStructTest(1024*1024*64); + vectorPoDStructTest(1024*1024*64); //######################################## auto vectorPoDChildTest = [&](size_t s)