3 #include "../utility/alignment.h"
54 return m_Block == rhs.m_Block;
59 return m_Block != rhs.m_Block;
62 #pragma region Allocation
67 if ((
size_t(m_Block->Free - m_Block->Data) + totalSize) > Size)
70 char* current = m_Block->Free;
72 m_Block->Free += totalSize;
73 m_Block->ObjectCount += totalSize;
82 if (m_Block->Free - totalSize == p)
83 m_Block->Free -= totalSize;
85 m_Block->ObjectCount -= totalSize;
88 if (m_Block->ObjectCount == 0)
89 m_Block->Free = m_Block->Data;
93 #pragma region Utility
99 bool owns(
void* p)
const noexcept
103 uintptr_t ptr =
reinterpret_cast<uintptr_t
>(p);
104 uintptr_t low =
reinterpret_cast<uintptr_t
>(m_Block->Data);
105 uintptr_t high = low + Size;
107 return ptr >= low && ptr < high;
A linear allocator which gives out chunks of its allocated stack. Increments a counter during allocat...
Definition: stack_allocator.h:36
bool operator!=(const stack_allocator &rhs) const noexcept
Definition: stack_allocator.h:57
void deallocate(void *p, size_t n) noexcept
Definition: stack_allocator.h:78
stack_allocator(stack_allocator &&) noexcept=default
stack_allocator(stack< Size > &block) noexcept
Definition: stack_allocator.h:38
size_t max_size() const noexcept
Definition: stack_allocator.h:94
stack_allocator(stack< Size > *block) noexcept
Definition: stack_allocator.h:41
bool owns(void *p) const noexcept
Definition: stack_allocator.h:99
void * allocate(size_t n) noexcept
Definition: stack_allocator.h:63
stack_allocator(const stack_allocator &) noexcept=default
constexpr size_t align_to_architecture(size_t n) noexcept
Definition: alignment.h:10
constexpr size_t ALIGNMENT
Definition: alignment.h:7
Definition: cascading.h:15
A stack object of a given Size.
Definition: stack_allocator.h:17
char Data[Size]
Definition: stack_allocator.h:18
char * Free
Definition: stack_allocator.h:19
size_t ObjectCount
Definition: stack_allocator.h:20
stack() noexcept
Definition: stack_allocator.h:22