Use Boost.Container's uses_allocator_construction utilities and update documentation to explain this feature

This commit is contained in:
Ion Gaztañaga
2025-12-19 10:13:45 +01:00
parent 520a41bfc9
commit 67aab58191
2 changed files with 36 additions and 14 deletions

View File

@@ -3419,6 +3419,8 @@ For more information about managed mapped file capabilities, see
[endsect]
[endsect]
[section:managed_memory_segment_features Managed Memory Segment Features]
The following features are common to all managed memory segment classes, but
@@ -3463,13 +3465,38 @@ of a managed memory segment or objects constructed in the managed segment.
[endsect]
[section:allocation_types Object construction function family]
[section:object_constrution Object construction and uses-allocator protocol]
[*Boost.Interprocess]' managed memory segments allows a varied object
construction styles: associated with a name, anonymous or "singleton-like"
objects.
The object construction API allows constructing both individual elements
and arrays of objects. An array can be constructed with the same
parameters for all objects within the array or we can define a different
parameter from a list of iterators.
Since Boost 1.91, [*Boost.Interprocess] uses [Boost.Container's]
extended uses-allocator construction utilities like `uninitialized_construct_using_allocator`
(see [@https://www.boost.org/doc/libs/latest/doc/html/container/cpp_conformance.html Boost.Container]
so that constructing objects that use shared-memory allocators is simplified. A
user taking advantage of the uses-allocator protocol:
* Does not longer need to explicitly pass allocator arguments when constructing an
object by means of the managed memory segment utilities.
* [*Boost.Inteprocess] allocators' `construct` operations, in cooperation with [*Boost.Containers]
take advantage of the uses-allocator protocol to automatically propagate the state of the shared
memory allocator to compatible types.
[endsect]
[section:named Named Object construction function family]
When constructing objects in a managed memory segment (managed shared memory,
managed mapped files...) associated with a name, the user has a varied object
construction family to "construct" or to "construct if not found". [*Boost.Interprocess]
can construct a single object or an array of objects. The array can be constructed with
the same parameters for all objects or we can define each parameter from a list of iterators:
can construct a single object or an array of objects.
[c++]
@@ -4428,8 +4455,6 @@ through a message queue and duplicated in another buffer:
[endsect]
[endsect]
[section:allocators_containers Allocators and memory allocation algorithms]
[section:allocator_introduction Introduction to Interprocess allocators]

View File

@@ -31,8 +31,9 @@
#include <boost/move/utility_core.hpp>
#include <boost/interprocess/detail/variadic_templates_tools.hpp>
#endif //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING
#include <boost/container/uses_allocator_construction.hpp>
#include <boost/container/detail/placement_new.hpp>
#include <boost/container/detail/dispatch_uses_allocator.hpp>
#include <boost/interprocess/allocators/detail/allocator_common.hpp>
#include <cstddef>
@@ -96,21 +97,17 @@ struct CtorArgN
template<class SegmentManager, std::size_t ...IdxPack>
void construct(void* mem, SegmentManager *segment_manager, true_, const index_tuple<IdxPack...>&)
{
boost::container::dtl::allocator_traits_dummy<T> atd;
typedef uses_segment_manager<SegmentManager> uses_segment_manager_t;
boost::container::dtl::dispatch_uses_allocator
(atd, uses_segment_manager_t(segment_manager), static_cast<T*>(mem), *boost::forward<Args>((get<IdxPack>)(args_))...);
boost::container::uninitialized_construct_using_allocator
(static_cast<T*>(mem), uses_segment_manager_t(segment_manager), *boost::forward<Args>((get<IdxPack>)(args_))...);
}
//{ ::new((void*)mem, boost_container_new_t()) T(*boost::forward<Args>((get<IdxPack>)(args_))...); }
template<class SegmentManager, std::size_t ...IdxPack>
void construct(void *mem, SegmentManager *segment_manager, false_, const index_tuple<IdxPack...>&)
{
typedef uses_segment_manager<SegmentManager> uses_segment_manager_t;
boost::container::dtl::allocator_traits_dummy<T> atd;
boost::container::dtl::dispatch_uses_allocator
(atd, uses_segment_manager_t(segment_manager), static_cast<T*>(mem), boost::forward<Args>((get<IdxPack>)(args_))...);
boost::container::uninitialized_construct_using_allocator
(static_cast<T*>(mem), uses_segment_manager_t(segment_manager), boost::forward<Args>((get<IdxPack>)(args_))...);
}
template<std::size_t ...IdxPack>