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

Implements a lock-free stack-based bump allocator. More...

#include <AllocatorStack.hpp>

Inheritance diagram for Foundation::Core::AllocatorStack:
Foundation::Core::Allocator

Public Member Functions

 AllocatorStack ()=default
 
 AllocatorStack (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) noexcept 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) noexcept override
 
pointer Reallocate (pointer ptr, size_type new_size, size_t alignment) noexcept 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)) noexcept=0
 
Arena AllocateArena (size_type size, size_t alignment)
 
Arena AllocateArena (size_type size)
 
void DeallocateArena (Arena arena)
 
AllocatorPtr ()
 

Private Attributes

pointer mMemory {nullptr}
 
Atomic< size_typemCurrent {}
 
size_type mEnd {}
 

Detailed Description

Implements a lock-free 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

◆ AllocatorStack() [1/2]

Foundation::Core::AllocatorStack::AllocatorStack ( )
default

◆ AllocatorStack() [2/2]

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

Member Function Documentation

◆ Allocate()

pointer Foundation::Core::AllocatorStack::Allocate ( size_type  size,
size_type  alignment 
)
overridenoexcept

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()

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

Implements Foundation::Core::Allocator.

◆ operator bool()

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

◆ Reallocate()

pointer Foundation::Core::AllocatorStack::Reallocate ( pointer  ptr,
size_type  new_size,
size_t  alignment 
)
inlineoverridevirtualnoexcept
Note
Unsupported.

Implements Foundation::Core::Allocator.

◆ Reset() [1/2]

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

Resets the stack allocator to a non-allocated state.

◆ Reset() [2/2]

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

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

Member Data Documentation

◆ mCurrent

Atomic<size_type> Foundation::Core::AllocatorStack::mCurrent {}
private

◆ mEnd

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

◆ mMemory

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

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