memory
Typedefs | Member Functions
static_allocator Class Reference

Detailed Description

A stateful RawAllocator that uses a fixed sized storage for the allocations.

It works on a static_allocator_storage and uses its memory for all allocations. Deallocations are not supported, memory cannot be marked as freed.

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

Typedefs

using is_stateful = std::true_type
 

Member Functions

template<std::size_t Size>
 static_allocator (static_allocator_storage< Size > &storage) noexcept
 
void * allocate_node (std::size_t size, std::size_t alignment)
 
void deallocate_node (void *, std::size_t, std::size_t) noexcept
 
std::size_t max_node_size () const noexcept
 
std::size_t max_alignment () const noexcept
 

Constructors

◆ static_allocator()

static_allocator ( static_allocator_storage< Size > &  storage)
noexcept
Effects:
Creates it by passing it a static_allocator_storage by reference. It will take the address of the storage and use its memory for the allocation.
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.

Member Functions

◆ allocate_node()

void * allocate_node ( std::size_t  size,
std::size_t  alignment 
)
Effects:
A RawAllocator allocation function. It uses the specified static_allocator_storage.
Returns:
A pointer to a node, it will never be nullptr.
Throws:
An exception of type out_of_memory or whatever is thrown by its handler if the storage is exhausted.

◆ deallocate_node()

void deallocate_node ( void *  ,
std::size_t  ,
std::size_t   
)
noexcept
Effects:
A RawAllocator deallocation function. It does nothing, deallocation is not supported by this allocator.

◆ max_node_size()

std::size_t max_node_size ( ) const
noexcept
Returns:
The maximum node size which is the capacity remaining inside the static_allocator_storage.

◆ max_alignment()

std::size_t max_alignment ( ) const
noexcept
Returns:
The maximum possible value since there is no alignment restriction (except indirectly through the size of the static_allocator_storage).