WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::allocator_storage< StoragePolicy, Mutex > Class Template Reference

A RawAllocator that stores another allocator. More...

#include <wpi/memory/allocator_storage.hpp>

Public Types

using allocator_type = typename StoragePolicy::allocator_type
 
using storage_policy = StoragePolicy
 
using mutex = Mutex
 
using is_stateful = typename traits::is_stateful
 

Public Member Functions

 allocator_storage ()=default
 
template<class Alloc >
 allocator_storage (Alloc &&alloc,)
 
template<class OtherPolicy >
 allocator_storage (const allocator_storage< OtherPolicy, Mutex > &other,)
 
bool is_composable () const noexcept
 
 allocator_storage (allocator_storage &&other) noexcept
 
allocator_storageoperator= (allocator_storage &&other) noexcept
 
 allocator_storage (const allocator_storage &)=default
 
allocator_storageoperator= (const allocator_storage &)=default
 
void * allocate_node (std::size_t size, std::size_t alignment)
 
void * allocate_array (std::size_t count, std::size_t size, std::size_t alignment)
 
void deallocate_node (void *ptr, std::size_t size, std::size_t alignment) noexcept
 
void deallocate_array (void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
std::size_t max_node_size () const
 
std::size_t max_array_size () const
 
std::size_t max_alignment () const
 
void * try_allocate_node (std::size_t size, std::size_t alignment) noexcept
 
void * try_allocate_array (std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
bool try_deallocate_node (void *ptr, std::size_t size, std::size_t alignment) noexcept
 
bool try_deallocate_array (void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
auto get_allocator () noexcept -> decltype(std::declval< storage_policy >().get_allocator())
 
auto get_allocator () const noexcept -> decltype(std::declval< const storage_policy >().get_allocator())
 
auto lock () noexcept -> implementation_defined
 
auto lock () const noexcept -> implementation_defined
 

Detailed Description

template<class StoragePolicy, class Mutex>
class wpi::memory::allocator_storage< StoragePolicy, Mutex >

A RawAllocator that stores another allocator.

The StoragePolicy defines the allocator type being stored and how it is stored. The Mutex controls synchronization of the access.

Member Typedef Documentation

◆ allocator_type

template<class StoragePolicy , class Mutex >
using wpi::memory::allocator_storage< StoragePolicy, Mutex >::allocator_type = typename StoragePolicy::allocator_type

◆ is_stateful

template<class StoragePolicy , class Mutex >
using wpi::memory::allocator_storage< StoragePolicy, Mutex >::is_stateful = typename traits::is_stateful

◆ mutex

template<class StoragePolicy , class Mutex >
using wpi::memory::allocator_storage< StoragePolicy, Mutex >::mutex = Mutex

◆ storage_policy

template<class StoragePolicy , class Mutex >
using wpi::memory::allocator_storage< StoragePolicy, Mutex >::storage_policy = StoragePolicy

Constructor & Destructor Documentation

◆ allocator_storage() [1/5]

template<class StoragePolicy , class Mutex >
wpi::memory::allocator_storage< StoragePolicy, Mutex >::allocator_storage ( )
default
Effects:
Creates it by default-constructing the StoragePolicy.
Requires:
The StoragePolicy must be default-constructible.
Notes:
The default constructor may create an invalid allocator storage not associated with any allocator. If that is the case, it must not be used.

◆ allocator_storage() [2/5]

template<class StoragePolicy , class Mutex >
template<class Alloc >
wpi::memory::allocator_storage< StoragePolicy, Mutex >::allocator_storage ( Alloc && alloc)
inline
Effects:
Creates it by passing it an allocator. The allocator will be forwarded to the StoragePolicy, it decides whether it will be moved, its address stored or something else.
Requires:
The expression new storage_policy(std::forward<Alloc>(alloc)) must be well-formed, otherwise this constructor does not participate in overload resolution.

◆ allocator_storage() [3/5]

template<class StoragePolicy , class Mutex >
template<class OtherPolicy >
wpi::memory::allocator_storage< StoragePolicy, Mutex >::allocator_storage ( const allocator_storage< OtherPolicy, Mutex > & other)
inline
Effects:
Creates it by passing it another allocator_storage with a different StoragePolicy but the same Mutex type. Initializes it with the result of other.get_allocator().
Requires:
The expression new storage_policy(other.get_allocator()) must be well-formed, otherwise this constructor does not participate in overload resolution.

◆ allocator_storage() [4/5]

template<class StoragePolicy , class Mutex >
wpi::memory::allocator_storage< StoragePolicy, Mutex >::allocator_storage ( allocator_storage< StoragePolicy, Mutex > && other)
inlinenoexcept
Effects:
Moves the allocator_storage object. A moved-out allocator_storage object must still store a valid allocator object.

◆ allocator_storage() [5/5]

template<class StoragePolicy , class Mutex >
wpi::memory::allocator_storage< StoragePolicy, Mutex >::allocator_storage ( const allocator_storage< StoragePolicy, Mutex > & )
default
Effects:
Copies the allocator_storage object.
Requires:
The StoragePolicy must be copyable.

Member Function Documentation

◆ allocate_array()

template<class StoragePolicy , class Mutex >
void * wpi::memory::allocator_storage< StoragePolicy, Mutex >::allocate_array ( std::size_t count,
std::size_t size,
std::size_t alignment )
inline

◆ allocate_node()

template<class StoragePolicy , class Mutex >
void * wpi::memory::allocator_storage< StoragePolicy, Mutex >::allocate_node ( std::size_t size,
std::size_t alignment )
inline
Effects:
Calls the function on the stored allocator. The Mutex will be locked during the operation.

◆ deallocate_array()

template<class StoragePolicy , class Mutex >
void wpi::memory::allocator_storage< StoragePolicy, Mutex >::deallocate_array ( void * ptr,
std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept

◆ deallocate_node()

template<class StoragePolicy , class Mutex >
void wpi::memory::allocator_storage< StoragePolicy, Mutex >::deallocate_node ( void * ptr,
std::size_t size,
std::size_t alignment )
inlinenoexcept

◆ get_allocator() [1/2]

template<class StoragePolicy , class Mutex >
auto wpi::memory::allocator_storage< StoragePolicy, Mutex >::get_allocator ( ) const -> decltype(std::declval<const storage_policy>().get_allocator())
inlinenoexcept

◆ get_allocator() [2/2]

template<class StoragePolicy , class Mutex >
auto wpi::memory::allocator_storage< StoragePolicy, Mutex >::get_allocator ( ) -> decltype(std::declval<storage_policy>().get_allocator())
inlinenoexcept
Effects:
Forwards to the StoragePolicy.
Returns:
Returns a reference to the stored allocator.
Note
This does not lock the Mutex.

◆ is_composable()

template<class StoragePolicy , class Mutex >
bool wpi::memory::allocator_storage< StoragePolicy, Mutex >::is_composable ( ) const
inlinenoexcept
Returns:
Whether or not the stored allocator is composable, that is you can use the compositioning functions.
Note
Due to type-erased allocators, this function can not be constexpr.

◆ lock() [1/2]

template<class StoragePolicy , class Mutex >
auto wpi::memory::allocator_storage< StoragePolicy, Mutex >::lock ( ) const -> implementation_defined
inlinenoexcept

◆ lock() [2/2]

template<class StoragePolicy , class Mutex >
auto wpi::memory::allocator_storage< StoragePolicy, Mutex >::lock ( ) -> implementation_defined
inlinenoexcept
Returns:
A proxy object that acts like a pointer to the stored allocator. It cannot be reassigned to point to another allocator object and only moving is supported, which is destructive. As long as the proxy object lives and is not moved from, the Mutex will be kept locked.

◆ max_alignment()

template<class StoragePolicy , class Mutex >
std::size_t wpi::memory::allocator_storage< StoragePolicy, Mutex >::max_alignment ( ) const
inline

◆ max_array_size()

template<class StoragePolicy , class Mutex >
std::size_t wpi::memory::allocator_storage< StoragePolicy, Mutex >::max_array_size ( ) const
inline

◆ max_node_size()

template<class StoragePolicy , class Mutex >
std::size_t wpi::memory::allocator_storage< StoragePolicy, Mutex >::max_node_size ( ) const
inline

◆ operator=() [1/2]

template<class StoragePolicy , class Mutex >
allocator_storage & wpi::memory::allocator_storage< StoragePolicy, Mutex >::operator= ( allocator_storage< StoragePolicy, Mutex > && other)
inlinenoexcept

◆ operator=() [2/2]

template<class StoragePolicy , class Mutex >
allocator_storage & wpi::memory::allocator_storage< StoragePolicy, Mutex >::operator= ( const allocator_storage< StoragePolicy, Mutex > & )
default

◆ try_allocate_array()

template<class StoragePolicy , class Mutex >
void * wpi::memory::allocator_storage< StoragePolicy, Mutex >::try_allocate_array ( std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept

◆ try_allocate_node()

template<class StoragePolicy , class Mutex >
void * wpi::memory::allocator_storage< StoragePolicy, Mutex >::try_allocate_node ( std::size_t size,
std::size_t alignment )
inlinenoexcept
Effects:
Calls the function on the stored composable allocator. The Mutex will be locked during the operation.
Requires:
The allocator must be composable, i.e. is_composable() must return true.
Note
This check is done at compile-time where possible, and at runtime in the case of type-erased storage.

◆ try_deallocate_array()

template<class StoragePolicy , class Mutex >
bool wpi::memory::allocator_storage< StoragePolicy, Mutex >::try_deallocate_array ( void * ptr,
std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept

◆ try_deallocate_node()

template<class StoragePolicy , class Mutex >
bool wpi::memory::allocator_storage< StoragePolicy, Mutex >::try_deallocate_node ( void * ptr,
std::size_t size,
std::size_t alignment )
inlinenoexcept

The documentation for this class was generated from the following file: