xentara-utils v2.0.3
The Xentara Utility Library
|
A memory resource that allocates an additional control block. More...
#include <xentara/utils/memory/ControlBlockMemoryResource.hpp>
Public Member Functions | |
ControlBlockMemoryResource (std::reference_wrapper< std::pmr::memory_resource > upstream= *std::pmr::get_default_resource()) | |
Constructor. | |
template<typename... ControlBlockArguments> requires std::is_constructible_v<ControlBlock, ControlBlockArguments &&...> | |
auto | allocate (std::size_t size, std::size_t alignment=alignof(std::max_align_t), ControlBlockArguments &&...controlBlockArguments) -> void * |
Allocates a block. | |
auto | deallocate (void *address, std::size_t size, std::size_t alignment=alignof(std::max_align_t)) -> void |
Deallocates a block previously allocated with allocate() | |
auto | upstream () const noexcept -> std::pmr::memory_resource & |
Gets the upstream memory resource. | |
auto | is_equal (const ControlBlockMemoryResource &other) const noexcept -> bool |
Determines if this memory resource is interchangable with another resource. | |
Static Public Member Functions | |
static auto | controlBlock (void *address) noexcept -> ControlBlock & |
Retreives the control block from a pointer to the allocated block. | |
static auto | payload (const ControlBlock &block) noexcept -> void * |
Returns a pointer to the allocated block belonging to a control block. | |
A memory resource that allocates an additional control block.
This class is just like a regular std::pmr::memory_resource, but allows you to add a control block to each allocated block. You can store meta-information or housekeeping information in the control block, without the client of the memory resource having to know about them. You can retreive the control block for an allocated block using the function controlBlock().
This class has a similar interface to std::pmr::memory_resource, but is not derived from it.
ControlBlock | The control block type |
xentara::utils::memory::ControlBlockMemoryResource< ControlBlock >::ControlBlockMemoryResource | ( | std::reference_wrapper< std::pmr::memory_resource > | upstream = *std::pmr::get_default_resource() | ) |
Constructor.
upstream | The upstream memory resource |
auto xentara::utils::memory::ControlBlockMemoryResource< ControlBlock >::allocate | ( | std::size_t | size, |
std::size_t | alignment = alignof(std::max_align_t) , |
||
ControlBlockArguments &&... | controlBlockArguments | ||
) | -> void * |
Allocates a block.
size | The number of bytes to allocate |
alignment | The alignment requirements of the block |
controlBlockArguments | Arguments to be forwarded to the constructor of the control block |
|
staticnoexcept |
Retreives the control block from a pointer to the allocated block.
auto xentara::utils::memory::ControlBlockMemoryResource< ControlBlock >::deallocate | ( | void * | address, |
std::size_t | size, | ||
std::size_t | alignment = alignof(std::max_align_t) |
||
) | -> void |
Deallocates a block previously allocated with allocate()
address | The address of the block, as returned by allocate() |
size | This must be the same value that was passed to allocate() when the block was allocated |
alignment | This must be the same value that was passed to allocate() when the block was allocated |
|
noexcept |
Determines if this memory resource is interchangable with another resource.
other | The other resource |
|
staticnoexcept |
Returns a pointer to the allocated block belonging to a control block.
|
noexcept |
Gets the upstream memory resource.