memory
|
A stateful RawAllocator that manages nodes of fixed size.
It uses a memory_arena with a given BlockOrRawAllocator
defaulting to growing_block_allocator, subdivides them in small nodes of given size and puts them onto a free list. Allocation and deallocation simply remove or add nodes from this list and are thus fast. The way the list is maintained can be controlled via the PoolType
which is either node_pool, array_pool or small_node_pool.
This kind of allocator is ideal for fixed size allocations and deallocations in any order, for example in a node based container like std::list
. It is not so good for different allocation sizes and has some drawbacks for arrays as described in memory_pool_type.hpp.
Typedefs | |
using | allocator_type = make_block_allocator_t< BlockOrRawAllocator > |
using | pool_type = PoolType |
Constants | |
static constexpr std::size_t | min_node_size |
Static Functions | |
static constexpr std::size_t | min_block_size (std::size_t node_size, std::size_t number_of_nodes) noexcept |
Member Functions | |
template<typename... Args> | |
memory_pool (std::size_t node_size, std::size_t block_size, Args &&... args) | |
~memory_pool () noexcept | |
void * | allocate_node () |
void * | try_allocate_node () noexcept |
void * | allocate_array (std::size_t n) |
void * | try_allocate_array (std::size_t n) noexcept |
void | deallocate_node (void *ptr) noexcept |
bool | try_deallocate_node (void *ptr) noexcept |
void | deallocate_array (void *ptr, std::size_t n) noexcept |
bool | try_deallocate_array (void *ptr, std::size_t n) noexcept |
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 (memory_pool &&other) noexcept | |
memory_pool & | operator= (memory_pool &&other) noexcept |
memory_pool | ( | std::size_t | node_size, |
std::size_t | block_size, | ||
Args &&... | args | ||
) |
node_size
is less than the min_node_size
, the min_node_size
will be the actual node size. It will allocate an initial memory block with given size from the BlockAllocator and puts it onto the free list. node_size
must be a valid node size and block_size
must be at least min_block_size(node_size, 1)
.
|
noexcept |
|
noexcept |
|
staticconstexprnoexcept |
node_size
must be a valid node size and number_of_nodes
must be a non-zero value. std::list
for example is never empty and always allocates proxy nodes. To get enough memory for N
elements of a list, number_of_nodes
needs to include the proxy count in addition to N
.
|
noexcept |
void * allocate_node | ( | ) |
sizeof(T) < node_size()
.
|
noexcept |
nullptr
. void * allocate_array | ( | std::size_t | n | ) |
n
continuous nodes on the 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, even if technically there is enough continuous memory on the free list. n
nodes of size node_size() suitable aligned. n * node_size()
is too big. n
must be valid array count.
|
noexcept |
n
nodes of size node_size() suitable aligned or nullptr
.
|
noexcept |
ptr
must be a result from a previous call to allocate_node() on the same free list, i.e. either this allocator object or a new object created by moving this to it.
|
noexcept |
true
if the node could be deallocated, false
otherwise.
|
noexcept |
ptr
must be a result from a previous call to allocate_array() with the same n
on the same free list, i.e. either this allocator object or a new object created by moving this to it.
|
noexcept |
true
if the node could be deallocated, false
otherwise.
|
noexcept |
min_node_size
if the value was too small.
|
noexcept |
|
noexcept |
|
noexcept |