Fixes #120 ("segment_manager customization")

This commit is contained in:
Ion Gaztañaga
2021-02-21 00:15:21 +01:00
parent cb30bb5f67
commit ece73cef73
3 changed files with 29 additions and 2 deletions

View File

@@ -6809,6 +6809,7 @@ thank them:
* [@https://github.com/boostorg/interprocess/pull/83 GitHub #83 (['"Add BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION option"])].
* [@https://github.com/boostorg/interprocess/pull/92 GitHub #92 (['"bufferstream: Correct MSVC compilation warning"])].
* [@https://github.com/boostorg/interprocess/pull/106 GitHub #106 (['"Use fallocate on truncate_file"])].
* [@https://github.com/boostorg/interprocess/issues/120 GitHub #120 (['"segment_manager customization"])].
* [@https://github.com/boostorg/interprocess/issues/122 GitHub #122 (['"Mark constructors/assignment/swap noexcept where possible"])].
* [@https://github.com/boostorg/interprocess/issues/126 GitHub #126 (['"_ReadWriteBarrier is deprecated warning when compiling with clang-cl.exe"])].

View File

@@ -127,6 +127,20 @@ class segment_manager_base
void * allocate (size_type nbytes, const std::nothrow_t &)
{ return MemoryAlgorithm::allocate(nbytes); }
//!Returns a reference to the internal memory algorithm.
//!This function is useful for custom memory algorithms that
//!need additional configuration options after construction. Never throws.
//!This function should be only used by advanced users.
MemoryAlgorithm &get_memory_algorithm()
{ return static_cast<MemoryAlgorithm&>(*this); }
//!Returns a const reference to the internal memory algorithm.
//!This function is useful for custom memory algorithms that
//!need additional configuration options after construction. Never throws.
//!This function should be only used by advanced users.
const MemoryAlgorithm &get_memory_algorithm() const
{ return static_cast<const MemoryAlgorithm&>(*this); }
#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
//Experimental. Dont' use.

View File

@@ -289,7 +289,7 @@ bool test_segment_manager()
return false;
typename SegmentManager::const_named_iterator nb(seg_mgr->named_begin());
typename SegmentManager::const_named_iterator ne(seg_mgr->named_end());
for(std::size_t i = 0, imax = seg_mgr->get_num_named_objects(); i != imax; ++i){ ++nb; }
for(std::size_t j = 0, imax = seg_mgr->get_num_named_objects(); j != imax; ++j){ ++nb; }
if(nb != ne)
return false;
seg_mgr->destroy_ptr(uint_object);
@@ -379,7 +379,7 @@ bool test_segment_manager()
return false;
typename SegmentManager::const_unique_iterator nb(seg_mgr->unique_begin());
typename SegmentManager::const_unique_iterator ne(seg_mgr->unique_end());
for(std::size_t i = 0, imax = seg_mgr->get_num_unique_objects(); i != imax; ++i){ ++nb; }
for(std::size_t j = 0, imax = seg_mgr->get_num_unique_objects(); j != imax; ++j){ ++nb; }
if(nb != ne)
return false;
seg_mgr->destroy_ptr(uint_object);
@@ -436,6 +436,18 @@ bool test_segment_manager()
if(!seg_mgr->all_memory_deallocated())
return false;
}
{//test get_memory_algorithm
{
typename SegmentManager::memory_algorithm & mem_algo =
seg_mgr->get_memory_algorithm();
boost::ignore_unused(mem_algo);
}
{
const typename SegmentManager::memory_algorithm & mem_algo =
const_cast<const SegmentManager*>(seg_mgr)->get_memory_algorithm();
boost::ignore_unused(mem_algo);
}
}
return true;
}