memory
Member Functions
static_block_allocator Class Reference

Detailed Description

A BlockAllocator that allocates the blocks from a fixed size storage.

It works on a static_allocator_storage and uses it for all allocations, deallocations are only allowed in reversed order which is guaranteed by memory_arena.

Note
It is not allowed to share an static_allocator_storage between multiple static_allocator objects.

Member Functions

template<std::size_t Size>
 static_block_allocator (std::size_t block_size, static_allocator_storage< Size > &storage) noexcept
 
memory_block allocate_block ()
 
void deallocate_block (memory_block block) noexcept
 
std::size_t next_block_size () const noexcept
 
 static_block_allocator (static_block_allocator &&other) noexcept
 
static_block_allocatoroperator= (static_block_allocator &&other) noexcept
 

Constructors

◆ static_block_allocator() [1/2]

static_block_allocator ( std::size_t  block_size,
static_allocator_storage< Size > &  storage 
)
noexcept
Effects:
Creates it by passing it the block size and a static_allocator_storage by reference. It will take the address of the storage and use it to allocate block_size'd blocks.
Requires:
The storage object must live as long as the allocator object. It must not be shared between multiple allocators, i.e. the object must not have been passed to a constructor before. The size of the static_allocator_storage must be a multiple of the (non-null) block size.

◆ static_block_allocator() [2/2]

Effects:
Moves the block allocator, it transfers ownership over the static_allocator_storage. This does not invalidate any memory blocks.

Member Functions

◆ operator=()

static_block_allocator & operator= ( static_block_allocator &&  other)
noexcept
Effects:
Moves the block allocator, it transfers ownership over the static_allocator_storage. This does not invalidate any memory blocks.

◆ allocate_block()

memory_block allocate_block ( )
Effects:
Allocates a new block by returning the next_block_size() bytes.
Returns:
The new memory block.

◆ deallocate_block()

void deallocate_block ( memory_block  block)
noexcept
Effects:
Deallocates the last memory block by marking the block as free again. This block will be returned again by the next call to allocate_block().
Requires:
block must be the current top block of the memory, this is guaranteed by memory_arena.

◆ next_block_size()

std::size_t next_block_size ( ) const
noexcept
Returns:
The next block size, this is the size passed to the constructor.