diff --git a/test/storage_adaptor_test.cpp b/test/storage_adaptor_test.cpp index d0a05300..7f4f67bb 100644 --- a/test/storage_adaptor_test.cpp +++ b/test/storage_adaptor_test.cpp @@ -247,28 +247,29 @@ int main() { tracing_allocator>>; using A = storage_adaptor; auto a = A(map(alloc)); + // MSVC implementation allocates some structures for debugging + const auto baseline = db.sum.first; a.reset(10); - BOOST_TEST_EQ(db.sum().first, 0); // nothing allocated yet + BOOST_TEST_EQ(db.sum.first, baseline); // nothing allocated yet BOOST_TEST_EQ(static_cast(a)[0], 0); // query on const reference does not allocate BOOST_TEST_EQ(a[9], 0); // query on writeable reference allocates - BOOST_TEST_EQ(db.sum().first, 1); + BOOST_TEST_EQ(db.sum.first, baseline + 1); a(5); BOOST_TEST_EQ(a[0], 0); BOOST_TEST_EQ(a[5], 1); BOOST_TEST_EQ(a[9], 0); - BOOST_TEST_EQ(db.sum().first, 3); + BOOST_TEST_EQ(db.sum.first, baseline + 3); a *= 2; BOOST_TEST_EQ(a[5], 2); - BOOST_TEST_EQ(db.sum().first, 3); + BOOST_TEST_EQ(db.sum.first, baseline + 3); auto b = storage_adaptor>(); b.reset(5); b(2); a = b; - BOOST_TEST_EQ(db.sum().second, 3); // old allocations were freed - BOOST_TEST_EQ(db.sum().first, 4); // only one new allocation for non-zero value + BOOST_TEST_EQ(db.sum.first, baseline + 4); // only one new allocation for non-zero value } return boost::report_errors(); diff --git a/test/utility_allocator.hpp b/test/utility_allocator.hpp index 6230f9ae..09b0165f 100644 --- a/test/utility_allocator.hpp +++ b/test/utility_allocator.hpp @@ -23,14 +23,7 @@ struct tracing_allocator_db : std::unordered_mapoperator[](&BOOST_CORE_TYPEID(T)); } - std::pair sum() { - std::pair result(0, 0); - for (const auto& p : *this) { - result.first += p.second.first; - result.second += p.second.second; - } - return result; - } + std::pair sum; }; template @@ -46,12 +39,12 @@ struct tracing_allocator { ~tracing_allocator() noexcept {} T* allocate(std::size_t n) { - if (db) { db->at().first += n; } + if (db) { db->at().first += n; db->sum.first += n; } return static_cast(::operator new(n * sizeof(T))); } void deallocate(T* p, std::size_t n) { - if (db) { db->at().second += n; } + if (db) { db->at().second += n; db->sum.second += n; } ::operator delete((void*)p); } };