Stack allocator. More...
#include <StackAllocator.hpp>
Classes | |
struct | AllocationRecord |
Allocation record. More... | |
struct | Conf |
Stack allocator configuration data. More... | |
Public Types | |
using | size_type = std::size_t |
Size type. | |
Public Member Functions | |
StackAllocator (Conf config=GetDefaultConf()) | |
Initializing constructor. | |
StackAllocator (const StackAllocator ©)=delete | |
Copy constructor. | |
StackAllocator (StackAllocator &&other)=delete | |
StackAllocator & | operator= (const StackAllocator &other)=delete |
Copy assignment operator. | |
StackAllocator & | operator= (StackAllocator &&other)=delete |
void * | Allocate (size_type size) |
Allocates an aligned block of memory of the given size. More... | |
void | Free (void *p) noexcept |
Frees the given pointer. | |
template<typename T > | |
T * | AllocateArray (size_type size) |
Allocates and array of the given size number of elements. | |
void | operator() (void *p) noexcept |
Functional operator for freeing memory allocated by this object. More... | |
auto | GetMaxAllocation () const noexcept |
Gets the max allocation. | |
auto | GetEntryCount () const noexcept |
Gets the current allocation record entry usage count. More... | |
auto | GetIndex () const noexcept |
Gets the current index location. More... | |
auto | GetAllocation () const noexcept |
Gets the total number of bytes that this object has currently allocated. | |
auto | GetPreallocatedSize () const noexcept |
Gets the preallocated size. | |
auto | GetMaxEntries () const noexcept |
Gets the max entries. | |
Static Public Member Functions | |
static constexpr Conf | GetDefaultConf () |
Gets the default configuration. | |
Private Attributes | |
char *const | m_data |
Data. | |
AllocationRecord *const | m_entries |
Entries. | |
size_type const | m_size |
Size. | |
size_type const | m_max_entries |
Max entries. | |
size_type | m_index = 0 |
Index. | |
size_type | m_allocation = 0 |
Allocation. | |
size_type | m_maxAllocation = 0 |
Max allocation. | |
size_type | m_entryCount = 0 |
Entry count. | |
Stack allocator.
This is a stack allocator used for fast per step allocations. You must nest allocate/free pairs. The code will assert if you try to interleave multiple allocate/free pairs.
std::unique_ptr()
Deleter requirement. void * StackAllocator::Allocate | ( | size_type | size | ) |
Allocates an aligned block of memory of the given size.
nullptr
otherwise. Referenced by AllocateArray().
|
inlinenoexcept |
Gets the current allocation record entry usage count.
|
inlinenoexcept |
Gets the current index location.
This represents the number of bytes used (of the storage allocated at construction time by this object). Storage remaining is calculated by subtracting this value from StackSize
.
StackSize
.
|
inlinenoexcept |
Functional operator for freeing memory allocated by this object.
This method frees memory (like called Free) and allows this object to be used as deleter to std::unique_ptr
.