23#ifndef INCLUDED_ALLOCATORS_DYNAMIC_ARENA
24#define INCLUDED_ALLOCATORS_DYNAMIC_ARENA
43template<
size_t BLOCK_SIZE>
56 debug_warn(
"DynamicArena failed to allocate chunk");
57 throw std::bad_alloc();
63 std::free(
static_cast<void*
>(
m_Data));
73 other.m_Data =
nullptr;
81 Block tmp(std::move(other));
126 void*
allocate(
size_t n,
const void*,
size_t alignment)
134 debug_warn(
"DynamicArena cannot allocate more than chunk size");
135 throw std::bad_alloc();
138 if (!
m_Blocks.back().Available(n, alignment))
141 return reinterpret_cast<void*
>(
m_Blocks.back().Allocate(n, alignment));
#define ROUND_UP(n, multiple)
Definition: bits.h:284
Definition: DynamicArena.h:48
uint8_t * m_Data
Definition: DynamicArena.h:110
~Block()
Definition: DynamicArena.h:61
Block(const Block &other)=delete
Block()
Definition: DynamicArena.h:50
Block & operator=(const Block &other)=delete
bool Available(size_t n, size_t alignment) const
Definition: DynamicArena.h:95
friend void swap(Block &lhs, Block &rhs)
Definition: DynamicArena.h:87
uint8_t * Allocate(size_t n, size_t alignment)
Definition: DynamicArena.h:100
size_t m_Size
Definition: DynamicArena.h:109
Block(Block &&other)
Definition: DynamicArena.h:69
Block & operator=(Block &&other)
Definition: DynamicArena.h:76
'Blind' memory allocator.
Definition: DynamicArena.h:45
DynamicArena()
Definition: DynamicArena.h:115
void * allocate(size_t n, const void *, size_t alignment)
Definition: DynamicArena.h:126
void clear()
Definition: DynamicArena.h:149
void deallocate(void *p, size_t n)
Definition: DynamicArena.h:144
std::vector< Block > m_Blocks
Definition: DynamicArena.h:156
NONCOPYABLE(DynamicArena)
void AllocateNewBlock()
Definition: DynamicArena.h:121
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:40
#define debug_warn(expr)
display the error dialog with the given text.
Definition: debug.h:319
Definition: allocator_policies.h:36
unsigned char uint8_t
Definition: wposix_types.h:51
static const size_t BLOCK_SIZE
Definition: write_buffer.cpp:32