This struct is an implementation of C++ standard library type std::allocator. It is to be used with container types provided by the C++ standard library in combination with ALib Allocators.
With the inclusion of module ALib Monomem in the ALib Build, this allocator is suitable to use cases of strict or weak monotonic allocation.
The following alias type definitions exist for this type, each addressing a specific allocator:
Along with this, shortcuts to the container types are likewise provided with:
While the dedicated container types provided with module ALib Containers offer a method named Reset (see, for example, HashTable::Reset), the C++ standard containers do not. This is a challenge because their internal memory will be invalid with a reset. For example, if allocator type MonoAllocator was used with class std::vector, there is no interface method that makes the vector "forget" its internal data array. Its method shrink_to_fit by its specification is not forced to shrink anything or even dispose the data if the size was 0 when called. This is implementation-dependent.
The way out is as simple as radical: The container is just to be destructed and reconstructed "in place". This can be done using a C++ placement-new. The following code snippet demonstrates this:
std::unordered_set and std::unordered_map), is provided with sibling type StdRecyclingAllocator.| T | The type of objects to be allocated. |
| TAllocator | The allocator type, as prototyped with Allocator. |
Definition at line 758 of file allocation.inl.
Public Type Index: | |
| using | AllocatorType = TAllocator |
| Exposes template parameter TAllocator. | |
| using | allocBase = AllocatorMember<TAllocator> |
| The type of the base class that stores the allocator. | |
| using | difference_type = std::ptrdiff_t |
| Type definition as required by C++ library standards. | |
| using | propagate_on_container_move_assignment = std::false_type |
| Type definition as required by C++ library standards. | |
| using | size_type = std::size_t |
| Type definition as required by C++ library standards. | |
| using | value_type = T |
| Type definition as required by C++ library standards. | |
Public Type Index: inherited from alib::lang::AllocatorMember< TAllocator > | |
| using | AllocatorType = TAllocator |
| Exposes the allocator type. | |
Public Method Index: | |
| constexpr | StdAllocator () noexcept=default |
| Parameterless constructor used with heap allocation. | |
| constexpr | StdAllocator (const StdAllocator &) noexcept=default |
| Defaulted copy constructor. | |
| template<typename TSibling> | |
| StdAllocator (const StdAllocator< TSibling, TAllocator > &origin) | |
| template<typename TSibling> requires alib::lang::IsAllocator<typename TSibling::allocator> | |
| constexpr | StdAllocator (const TSibling &origin) noexcept |
| constexpr | StdAllocator (StdAllocator &&) noexcept=default |
| Defaulted move constructor. | |
| constexpr | StdAllocator (TAllocator &pAllocator) noexcept |
| constexpr | ~StdAllocator () noexcept=default |
| Parameterless destructor used with heap allocation. | |
| constexpr T * | allocate (size_t n) |
| constexpr std::allocation_result< T *, std::size_t > | allocate_at_least (std::size_t n) |
| constexpr void | deallocate (T *p, std::size_t n) |
Public Method Index: inherited from alib::lang::AllocatorMember< TAllocator > | |
| template<typename TIf = TAllocator> requires std::is_default_constructible_v<TIf> | |
| AllocatorMember () | |
| AllocatorMember (TAllocator &pAllocator) noexcept | |
| AllocatorInterface< TAllocator > | AI () const noexcept |
| TAllocator & | GetAllocator () const noexcept |
Additional Inherited Members | |
Protected Field Index: inherited from alib::lang::AllocatorMember< TAllocator > | |
| TAllocator * | allocator |
| The allocator stored. | |
| using alib::lang::StdAllocator< T, TAllocator >::AllocatorType = TAllocator |
Exposes template parameter TAllocator.
Definition at line 766 of file allocation.inl.
| using alib::lang::StdAllocator< T, TAllocator >::allocBase = AllocatorMember<TAllocator> |
The type of the base class that stores the allocator.
Definition at line 769 of file allocation.inl.
| using alib::lang::StdAllocator< T, TAllocator >::difference_type = std::ptrdiff_t |
Type definition as required by C++ library standards.
Definition at line 762 of file allocation.inl.
| using alib::lang::StdAllocator< T, TAllocator >::propagate_on_container_move_assignment = std::false_type |
Type definition as required by C++ library standards.
Definition at line 763 of file allocation.inl.
| using alib::lang::StdAllocator< T, TAllocator >::size_type = std::size_t |
Type definition as required by C++ library standards.
Definition at line 761 of file allocation.inl.
| using alib::lang::StdAllocator< T, TAllocator >::value_type = T |
Type definition as required by C++ library standards.
Definition at line 760 of file allocation.inl.
|
inlineconstexprnoexcept |
Constructor for the initial allocator instantiation.
| pAllocator | The allocator. |
Definition at line 777 of file allocation.inl.
|
inlineconstexprnoexcept |
Copy constructor using an instance of a different template type.
| TSibling | The originating allocator's type (StdAllocator<X>). |
| origin | The originating allocator of type TSibling . |
Definition at line 792 of file allocation.inl.
|
inline |
Copy constructor using an instance of a different template type.
| TSibling | The originating allocator's type (StdAllocator<X>). |
| origin | The originating allocator of type TSibling . |
Definition at line 799 of file allocation.inl.
|
inlinenodiscardconstexpr |
Passes the allocation request to the AllocatorMember.
| n | The number of requested objects to allocate storage for. |
Definition at line 813 of file allocation.inl.
|
inlinenodiscardconstexpr |
The C++23 extension of std::allocator finally supports ALib mechanics of using oversized allocation objects.
| n | The number of requested objects to allocate storage for. |
Definition at line 823 of file allocation.inl.
|
inlineconstexpr |
Frees the given array of objects.
| p | Pointer to the previously allocated memory. |
| n | The number of objects allocated. |
Definition at line 837 of file allocation.inl.