template<class PoolType = node_pool, class ImplAllocator = default_allocator>
class foonathan::memory::bucket_allocator< PoolType, ImplAllocator >
An alias for memory_pool_collection using the identity_buckets policy and a PoolType
defaulting to node_pool.
◆ allocate_node()
void* allocate_node |
( |
std::size_t |
node_size | ) |
|
|
inherited |
- Effects:
- Allocates a node of given size. It first finds the appropriate free list as defined in the
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.
- Returns:
- A node of given size suitable aligned, i.e. suitable for any type where
sizeof(T) < node_size
.
- Throws:
- Anything thrown by the BlockAllocator if a growth is needed or a bad_node_size exception if the node size is too big.
◆ try_allocate_node()
void* try_allocate_node |
( |
std::size_t |
node_size | ) |
|
|
noexceptinherited |
- Effects:
- Allocates a node of given size. It is similar to allocate_node() but will return
nullptr
on any failure, instead of growing the arnea and possibly throwing.
- Returns:
- A node of given size suitable aligned or
nullptr
in case of failure.
◆ allocate_array()
void* allocate_array |
( |
std::size_t |
count, |
|
|
std::size_t |
node_size |
|
) |
| |
|
inherited |
- Effects:
- Allocates an array of nodes by searching for
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().
- Returns:
- An array of
n
nodes of size node_size
suitable aligned.
- Throws:
- Anything thrown by the used BlockAllocator's allocation function if a growth is needed, or a bad_allocation_size exception.
- Requires:
count
must be valid array count and node_size
must be valid node size.
◆ try_allocate_array()
void* try_allocate_array |
( |
std::size_t |
count, |
|
|
std::size_t |
node_size |
|
) |
| |
|
noexceptinherited |
- Effects:
- Allocates a array of given size. It is similar to allocate_node() but will return
nullptr
on any failure, instead of growing the arnea and possibly throwing.
- Returns:
- A array of given size suitable aligned or
nullptr
in case of failure.
◆ deallocate_node()
void deallocate_node |
( |
void * |
ptr, |
|
|
std::size_t |
node_size |
|
) |
| |
|
noexceptinherited |
- Effects:
- Deallocates a node by putting it back onto the appropriate free list.
- Requires:
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.
◆ try_deallocate_node()
bool try_deallocate_node |
( |
void * |
ptr, |
|
|
std::size_t |
node_size |
|
) |
| |
|
noexceptinherited |
- Effects:
- Deallocates a node similar to deallocate_node(). But it checks if it can deallocate this memory.
- Returns:
true
if the node could be deallocated, false
otherwise.
◆ deallocate_array()
void deallocate_array |
( |
void * |
ptr, |
|
|
std::size_t |
count, |
|
|
std::size_t |
node_size |
|
) |
| |
|
noexceptinherited |
- Effects:
- Deallocates an array by putting it back onto the free list.
- Requires:
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.
◆ try_deallocate_array()
bool try_deallocate_array |
( |
void * |
ptr, |
|
|
std::size_t |
count, |
|
|
std::size_t |
node_size |
|
) |
| |
|
noexceptinherited |
- Effects:
- Deallocates a array similar to deallocate_array(). But it checks if it can deallocate this memory.
- Returns:
true
if the array could be deallocated, false
otherwise.
◆ reserve()
void reserve |
( |
std::size_t |
node_size, |
|
|
std::size_t |
capacity |
|
) |
| |
|
inherited |
- Effects:
- Inserts more memory on the free list for nodes of given size. It will try to put
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.
- Throws:
- Anything thrown by the BlockAllocator if a growth is needed.
- Requires:
node_size
must be valid node size less than or equal to max_node_size(), capacity_left
must be less than next_capacity().
◆ max_node_size()
std::size_t max_node_size |
( |
| ) |
const |
|
noexceptinherited |
- Returns:
- The maximum node size for which is a free list. This is the value passed to it in the constructor.
◆ pool_capacity_left()
std::size_t pool_capacity_left |
( |
std::size_t |
node_size | ) |
const |
|
noexceptinherited |
- Returns:
- The amount of nodes available in the free list for nodes of given size as defined over the
BucketDistribution
. This is the number of nodes that can be allocated without the free list requesting more memory from the arena.
- Note
- Array allocations may lead to a growth even if the capacity_left is big enough.
◆ capacity_left()
std::size_t capacity_left |
( |
| ) |
const |
|
noexceptinherited |
- Returns:
- The amount of memory available in the arena not inside the free lists. This is the number of bytes that can be inserted into the free lists without requesting more memory from the BlockAllocator.
- Note
- Array allocations may lead to a growth even if the capacity is big enough.
◆ next_capacity()
std::size_t next_capacity |
( |
| ) |
const |
|
noexceptinherited |
- Returns:
- The size of the next memory block after capacity_left() arena grows. This is the amount of memory that can be distributed in the pools.
- Note
- If the
PoolType
is small_node_pool, the exact usable memory is lower than that.
◆ get_allocator()
allocator_type& get_allocator |
( |
| ) |
|
|
noexceptinherited |
- Returns:
- A reference to the BlockAllocator used for managing the arena.
- Requires:
- It is undefined behavior to move this allocator out into another object.