Documentation of memory

( foonathan/memory)

bucket_allocator< PoolType, ImplAllocator > Class Template Reference

Detailed Description

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.

Typedefs

using allocator_type = make_block_allocator_t< ImplAllocator >
 
using pool_type = PoolType
 
using bucket_distribution = identity_buckets
 

Member Functions

void * allocate_node (std::size_t node_size)
 
void * allocate_array (std::size_t count, std::size_t node_size)
 
void 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
 
void reserve (std::size_t node_size, std::size_t capacity)
 
std::size_t max_node_size () const noexcept
 
std::size_t pool_capacity (std::size_t node_size) const noexcept
 
std::size_t capacity () const noexcept
 
std::size_t next_capacity () const noexcept
 
allocator_type & get_allocator () noexcept
 

Member Functions

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.
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.
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.
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.
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().
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.
std::size_t pool_capacity ( 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.
std::size_t capacity ( ) 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_left is big enough.
std::size_t next_capacity ( ) const
noexceptinherited
Returns:
The size of the next memory block after the free list gets empty and the arena grows. This function just forwards to the memory_arena.
Note
Due to fence memory, alignment buffers and the like this may not be the exact result capacity() will return, but it is an upper bound to it.
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.