Foundation
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Foundation::Core::StackAllocator Class Reference

Implements an atomic stack-based bump allocator. More...

#include <StackAllocator.hpp>

Inheritance diagram for Foundation::Core::StackAllocator:
Foundation::Core::Allocator

Public Member Functions

 StackAllocator ()=default
 
 StackAllocator (Arena arena)
 
void Reset (Arena arena)
 Resets the stack allocator to the initial state, allowing for reuse of the memory block (Arena)
 
void Reset ()
 Resets the stack allocator to a non-allocated state.
 
pointer Allocate (size_type size, size_type alignment) override
 Allocates a block of memory of the specified size with alignment. If the requested size exceeds the available memory within the arena, returns nullptr.
 
void Deallocate (pointer ptr) override
 
void Deallocate (pointer ptr, size_type size) override
 
pointer Reallocate (pointer ptr, size_type new_size, size_t alignment) override
 
constexpr operator bool () const noexcept
 
- Public Member Functions inherited from Foundation::Core::Allocator
virtual ~Allocator ()=default
 
virtual pointer Allocate (size_type size, size_t alignment=alignof(std::max_align_t))=0
 
Arena AllocateArena (size_type size, size_t alignment)
 
Arena AllocateArena (size_type size)
 
void DeallocateArena (Arena arena)
 
AllocatorPtr ()
 

Private Attributes

pointer mMemory { nullptr }
 
std::atomic< size_typemCurrent {}
 
size_type mEnd {}
 

Detailed Description

Implements an atomic stack-based bump allocator.

Note
This implementation is thread-safe for allocations from multiple threads. Deallocation is a no-op and does not modify the internal state.

Constructor & Destructor Documentation

◆ StackAllocator() [1/2]

Foundation::Core::StackAllocator::StackAllocator ( )
default

◆ StackAllocator() [2/2]

Foundation::Core::StackAllocator::StackAllocator ( Arena  arena)
inline

Member Function Documentation

◆ Allocate()

pointer Foundation::Core::StackAllocator::Allocate ( size_type  size,
size_type  alignment 
)
override

Allocates a block of memory of the specified size with alignment. If the requested size exceeds the available memory within the arena, returns nullptr.

◆ Deallocate() [1/2]

void Foundation::Core::StackAllocator::Deallocate ( pointer  ptr)
inlineoverridevirtual
Note
No-op. No memory is modified with this operation.

Implements Foundation::Core::Allocator.

◆ Deallocate() [2/2]

void Foundation::Core::StackAllocator::Deallocate ( pointer  ptr,
size_type  size 
)
inlineoverridevirtual
Note
No-op. No memory is modified with this operation.

Implements Foundation::Core::Allocator.

◆ operator bool()

constexpr Foundation::Core::StackAllocator::operator bool ( ) const
inlineconstexprnoexcept

◆ Reallocate()

pointer Foundation::Core::StackAllocator::Reallocate ( pointer  ptr,
size_type  new_size,
size_t  alignment 
)
inlineoverridevirtual
Note
Unsupported. Throws std::runtime_error when invoked.

Implements Foundation::Core::Allocator.

◆ Reset() [1/2]

void Foundation::Core::StackAllocator::Reset ( )
inline

Resets the stack allocator to a non-allocated state.

◆ Reset() [2/2]

void Foundation::Core::StackAllocator::Reset ( Arena  arena)
inline

Resets the stack allocator to the initial state, allowing for reuse of the memory block (Arena)

Member Data Documentation

◆ mCurrent

std::atomic<size_type> Foundation::Core::StackAllocator::mCurrent {}
private

◆ mEnd

size_type Foundation::Core::StackAllocator::mEnd {}
private

◆ mMemory

pointer Foundation::Core::StackAllocator::mMemory { nullptr }
private

The documentation for this class was generated from the following files: