diff --git a/doc/interprocess.qbk b/doc/interprocess.qbk index 5313a6c..3ccc12b 100644 --- a/doc/interprocess.qbk +++ b/doc/interprocess.qbk @@ -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"])]. diff --git a/include/boost/interprocess/segment_manager.hpp b/include/boost/interprocess/segment_manager.hpp index 14b11cb..283cd32 100644 --- a/include/boost/interprocess/segment_manager.hpp +++ b/include/boost/interprocess/segment_manager.hpp @@ -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(*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(*this); } + #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) //Experimental. Dont' use. diff --git a/test/segment_manager_test.cpp b/test/segment_manager_test.cpp index a440def..f22eca0 100644 --- a/test/segment_manager_test.cpp +++ b/test/segment_manager_test.cpp @@ -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(seg_mgr)->get_memory_algorithm(); + boost::ignore_unused(mem_algo); + } + } return true; }