45 if (size > std::numeric_limits<size_t>::max() / 2)
48 const size_t minimumAlloc = 16 * 1024 -
sizeof(
Block) - 16;
49 size = std::max(size, minimumAlloc);
54 if (size > std::numeric_limits<size_t>::max() -
sizeof(
Block))
65 char* buffer =
new char[size +
sizeof(
Block)];
106 bool Arena::Block::debugIsValid(
const void* ptr)
const {
107 return _blockBegin <= ptr && ptr < _freeBegin;
This is an arena allocator.
struct Arena::Block _block
void freeAndAllAfterFromOldBlock(void *ptr)
As Arena::freeAndAllAfter where ptr was allocated from an old block.
static Arena _scratchArena
void discardPreviousBlock()
Free the memory for the previous block.
void freeTopFromOldBlock(void *ptr)
As Arena::freeTop where ptr was allocated from an old block.
void growCapacity(size_t needed)
Allocate a new block with at least needed bytes.
static const size_t MemoryAlignment
The alignment that memory allocators must ensure.
bool hasPreviousBlock() const
Block * _previousBlock
one past last byte (aligned)
char * _blockEnd
pointer to first free byte (aligned)
char * _freeBegin
beginning of current block (aligned)
bool isInBlock(const void *ptr) const