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_tusing pointer_type = std::byte *using marker_type = MarkerPrivate Attributes
Public Member Functions
LinearAllocator()=defaultLinearAllocator(void *inBuffer, std::size_t inSize)LinearAllocator(LinearAllocator const &)=deleteLinearAllocator & operator=(LinearAllocator const &)=deleteLinearAllocator(LinearAllocator &&inOther)LinearAllocator & operator=(LinearAllocator &&inOther)void * Alloc(size_type inBytes, size_type inAlign=DEF_ALIGN) noexceptAllocates N bytes from the buffer with the given alignment.
inBytes | Number of bytes to allocate |
inAlign | Required address alignment ( default to platform alignment ) |
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).
T | Type to allocate and construct |
_Args | Constructor argument types (deduced) |
inArgs | Arguments forwarded to T's constructor. |
Pointer to the fully constructed T object.
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).
T | Element type. |
inCount | Number of elements. |
Pointer to the first element of the array.
std::bad_alloc | if the arena is full. |
marker_type GetMarker() const noexceptvoid Rewind(marker_type inMarker)Rewinds the allocator to a given offset.
inMarker | A previously created checkpoint |
Assertion | error if the marker is from the future. |
void Reset() noexceptbool Empty() const noexcept