![]() |
WPILibC++ 2025.3.2
|
A stateful RawAllocator that behaves as a collection of multiple memory_pool objects. More...
#include <wpi/memory/memory_pool_collection.hpp>
Public Types | |
| using | allocator_type = make_block_allocator_t<BlockOrRawAllocator> |
| using | pool_type = PoolType |
| using | bucket_distribution = BucketDistribution |
Public Member Functions | |
| template<typename... Args> | |
| memory_pool_collection (std::size_t max_node_size, std::size_t block_size, Args &&... args) | |
| ~memory_pool_collection () noexcept=default | |
| void * | allocate_node (std::size_t node_size) |
| void * | try_allocate_node (std::size_t node_size) noexcept |
| void * | allocate_array (std::size_t count, std::size_t node_size) |
| void * | try_allocate_array (std::size_t count, std::size_t node_size) noexcept |
| void | deallocate_node (void *ptr, std::size_t node_size) noexcept |
| bool | try_deallocate_node (void *ptr, std::size_t node_size) noexcept |
| void | deallocate_array (void *ptr, std::size_t count, std::size_t node_size) noexcept |
| bool | try_deallocate_array (void *ptr, std::size_t count, std::size_t node_size) noexcept |
| void | reserve (std::size_t node_size, std::size_t capacity) |
| std::size_t | max_node_size () const noexcept |
| std::size_t | pool_capacity_left (std::size_t node_size) const noexcept |
| std::size_t | capacity_left () const noexcept |
| std::size_t | next_capacity () const noexcept |
| allocator_type & | get_allocator () noexcept |
| memory_pool_collection (memory_pool_collection &&other) noexcept | |
| memory_pool_collection & | operator= (memory_pool_collection &&other) noexcept |
A stateful RawAllocator that behaves as a collection of multiple memory_pool objects.
It maintains a list of multiple free lists, whose types are controlled via the PoolType tags defined in memory_pool_type.hpp, each of a different size as defined in the BucketDistribution (identity_buckets or log2_buckets). Allocating a node of given size will use the appropriate free list.
This allocator is ideal for node allocations in any order but with a predefined set of sizes, not only one size like memory_pool.
| using wpi::memory::memory_pool_collection< PoolType, BucketDistribution, BlockOrRawAllocator >::allocator_type = make_block_allocator_t<BlockOrRawAllocator> |
| using wpi::memory::memory_pool_collection< PoolType, BucketDistribution, BlockOrRawAllocator >::bucket_distribution = BucketDistribution |
| using wpi::memory::memory_pool_collection< PoolType, BucketDistribution, BlockOrRawAllocator >::pool_type = PoolType |
|
inline |
BucketDistribution controls how many free lists are created, but unlike in memory_pool all free lists are initially empty and the first memory block queued. block_size must be non-zero and max_node_size must be a valid node size and smaller than block_size divided by the number of pools.
|
defaultnoexcept |
|
inlinenoexcept |
|
inline |
n continuous nodes on the appropriate free list and removing them. Depending on the PoolType this can be a slow operation or not allowed at all. This can sometimes lead to a growth on the free list, even if technically there is enough continuous memory on the free list. Otherwise has the same behavior as allocate_node(). n nodes of size node_size suitable aligned. count must be valid array count and node_size must be valid node size.
|
inline |
BucketDistribution. If it is empty, it will use an implementation defined amount of memory from the arena and inserts it in it. If the arena is empty too, it will request a new memory block from the BlockAllocator of size next_capacity() and puts part of it onto this free list. Then it removes a node from it. sizeof(T) < node_size.
|
inlinenoexcept |
|
inlinenoexcept |
ptr must be a result from a previous call to allocate_array() with the same sizes on the same free list, i.e. either this allocator object or a new object created by moving this to it.
|
inlinenoexcept |
ptr must be a result from a previous call to allocate_node() with the same size on the same free list, i.e. either this allocator object or a new object created by moving this to it.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
PoolType is small_node_pool, the exact usable memory is lower than that.
|
inlinenoexcept |
|
inlinenoexcept |
BucketDistribution. This is the number of nodes that can be allocated without the free list requesting more memory from the arena.
|
inline |
capacity_left bytes from the arena onto the free list defined over the BucketDistribution, if the arena is empty, a new memory block is requested from the BlockAllocator and it will be used. node_size must be valid node size less than or equal to max_node_size(), capacity_left must be less than next_capacity().
|
inlinenoexcept |
nullptr on any failure, instead of growing the arnea and possibly throwing. nullptr in case of failure.
|
inlinenoexcept |
nullptr on any failure, instead of growing the arnea and possibly throwing. nullptr in case of failure.
|
inlinenoexcept |
true if the array could be deallocated, false otherwise.
|
inlinenoexcept |
true if the node could be deallocated, false otherwise.