Implemented proposed resolution for LWG 3120

This commit is contained in:
Ion Gaztañaga
2018-06-18 00:29:22 +02:00
parent 62a8b6666e
commit 920e009d71
4 changed files with 49 additions and 17 deletions
+33 -13
View File
@@ -404,21 +404,41 @@ void test_do_is_equal()
void test_release()
{
memory_resource_logger mrl;
const std::size_t initial_size = 1u;
derived_from_monotonic_buffer_resource dmbr(initial_size, &mrl);
//First test, no buffer
const unsigned iterations = 8;
//Test each iteration allocates memory
for(unsigned i = 0; i != iterations; ++i)
{
dmbr.do_allocate(dmbr.remaining_storage()+1, 1);
BOOST_TEST(mrl.m_info.size() == (i+1));
memory_resource_logger mrl;
const std::size_t initial_size = 1u;
derived_from_monotonic_buffer_resource dmbr(initial_size, &mrl);
//First test, no buffer
const unsigned iterations = 8;
//Test each iteration allocates memory
for(unsigned i = 0; i != iterations; ++i)
{
dmbr.do_allocate(dmbr.remaining_storage()+1, 1);
BOOST_TEST(mrl.m_info.size() == (i+1));
}
//Release and check memory was released
dmbr.release();
BOOST_TEST(mrl.m_mismatches == 0u);
BOOST_TEST(mrl.m_info.size() == 0u);
}
//Now use a local buffer
{
boost::move_detail::aligned_storage
<monotonic_buffer_resource::initial_next_buffer_size>::type buf;
//Supply an external buffer
monotonic_buffer_resource monr(&buf, sizeof(buf));
memory_resource &mr = monr;
BOOST_TEST(monr.remaining_storage(1u) == sizeof(buf));
//Allocate all remaining storage
mr.allocate(monr.remaining_storage(1u), 1u);
BOOST_TEST(monr.current_buffer() == ((char*)&buf + sizeof(buf)));
//No new allocation should have ocurred
BOOST_TEST(monr.remaining_storage(1u) == 0u);
//Release and check memory was released and the original buffer is back
monr.release();
BOOST_TEST(monr.remaining_storage(1u) == sizeof(buf));
BOOST_TEST(monr.current_buffer() == &buf);
}
//Release and check memory was released
dmbr.release();
BOOST_TEST(mrl.m_mismatches == 0u);
BOOST_TEST(mrl.m_info.size() == 0u);
}
void test_destructor()