← API Reference Class

asge::mem::LinearAllocator

Arena allocator that bumps a pointer through a fixed-size buffer.

#include <LinearAllocator.hpp>

Inherited by asge::mem::ArenaAllocator, asge::mem::StackBuffer< N >.

Inheritance

classDiagram
    class N2["asge::mem::ArenaAllocator"]
    class N1["asge::mem::LinearAllocator"]
    class N3["asge::mem::StackBuffer"]
    N1 <|-- N2
    N1 <|-- N3
    click N2 href "classasge_1_1mem_1_1ArenaAllocator.html"
    click N1 href "classasge_1_1mem_1_1LinearAllocator.html"
    click N3 href "classasge_1_1mem_1_1StackBuffer.html"

Allocations are O(1) and never fragment — the offset only moves forward. Memory can be reclaimed in bulk via Reset() or rolled back to a saved Marker via Rewind(). Individual frees are not supported.

It does not own the buffer, hence it must be created outside of the allocator.

Public Types

#using size_type = std::size_t
#using pointer_type = std::byte *
#using marker_type = Marker

Private Attributes

#std::byte * m_Baseprivate
#std::size_t m_Sizeprivate
#std::size_t m_Offset {0}private

Public Member Functions

#LinearAllocator()=default
#LinearAllocator(void *inBuffer, std::size_t inSize)
#LinearAllocator(LinearAllocator const &)=delete
#LinearAllocator & operator=(LinearAllocator const &)=delete
#LinearAllocator(LinearAllocator &&inOther)
#LinearAllocator & operator=(LinearAllocator &&inOther)
#void * Alloc(size_type inBytes, size_type inAlign=DEF_ALIGN) noexcept

Allocates N bytes from the buffer with the given alignment.

Parameters
inBytes

Number of bytes to allocate

inAlign

Required address alignment ( default to platform alignment )

Returns

Pointer to the allocated region or nullptr

#template<typename T, typename ... _Args> T * AllocOne(_Args &&... inArgs)

Allocates memory for one object of type T.

It allocates memory for one object of type T and constructs it in-place using placement new and input arguments. Alignment is automatically derived from alignof(T).

Template Parameters
T

Type to allocate and construct

_Args

Constructor argument types (deduced)

Parameters
inArgs

Arguments forwarded to T's constructor.

Returns

Pointer to the fully constructed T object.

Exceptions
std::bad_alloc

if the allocator is full.

#template<typename T> T * AllocArray(size_type inCount)

Allocates an array of objects of type T.

Allocates a contiguous array of N objects of type T. For non-trivial types, each element is default-constructed via placement new. For trivial types (int, float, POD structs), construction is skipped entirely for maximum speed.

Alignment is automatically derived from alignof(T).

Template Parameters
T

Element type.

Parameters
inCount

Number of elements.

Returns

Pointer to the first element of the array.

Exceptions
std::bad_alloc

if the arena is full.

#marker_type GetMarker() const noexcept
#void Rewind(marker_type inMarker)

Rewinds the allocator to a given offset.

Parameters
inMarker

A previously created checkpoint

Exceptions
Assertion

error if the marker is from the future.

#void Reset() noexcept
#size_type Used() const noexcept
#size_type Remaining() const noexcept
#size_type Capacity() const noexcept
#bool Empty() const noexcept