memory
Typedefs | Member Functions
fixed_block_allocator< RawAllocator > Class Template Reference

Detailed Description

template<class RawAllocator = default_allocator>
class foonathan::memory::fixed_block_allocator< RawAllocator >

A BlockAllocator that allows only one block allocation.

It can be used to prevent higher-level allocators from expanding. The one block allocation is performed through the allocate_array() function of the given RawAllocator.

Typedefs

using allocator_type = typename traits::allocator_type
 

Member Functions

 fixed_block_allocator (std::size_t block_size, allocator_type alloc=allocator_type()) noexcept
 
memory_block allocate_block ()
 
void deallocate_block (memory_block block) noexcept
 
std::size_t next_block_size () const noexcept
 
allocator_type & get_allocator () noexcept
 

Constructors

◆ fixed_block_allocator()

fixed_block_allocator ( std::size_t  block_size,
allocator_type  alloc = allocator_type() 
)
explicitnoexcept
Effects:
Creates it by passing it the size of the block and the allocator object.
Requires:
block_size must be greater than 0,

Member Functions

◆ allocate_block()

memory_block allocate_block ( )
Effects:
Allocates a new memory block or throws an exception if there was already one allocation.
Returns:
The new memory_block.
Throws:
Anything thrown by the allocate_array() function of the RawAllocator or out_of_memory if this is not the first call.

◆ deallocate_block()

void deallocate_block ( memory_block  block)
noexcept
Effects:
Deallocates the previously allocated memory block. It also resets and allows a new call again.

◆ next_block_size()

std::size_t next_block_size ( ) const
noexcept
Returns:
The size of the next block which is either the initial size or 0.

◆ get_allocator()

allocator_type & get_allocator ( )
noexcept
Returns:
A reference to the used RawAllocator object.