parserino.arena

A bump allocator: many small allocations, freed all together.

It also works at compile time (CTFE), where it falls back to the GC, so the same parsing code can run both at runtime and at compile time.

Types 2

structArena

The bump allocator: memory comes from zeroed blocks (4 KB, doubling up to 16 KB, or bigger for a bigger allocation) that are freed all together by release or the destructor. An Arena can't be copied.

Methods
T[] alloc(T)(size_t n) @nogc nothrow pure @safe @trustedAllocate `n` zeroed `T`s. It returns `null` if out of memory.
T * make(T)() @nogc nothrow pure @safe @trustedAllocate a single zeroed `T`.
T[] dup(T)(scope const(T)[] src) @nogc nothrow pure @safe @trustedCopy an array into the arena.
void reserve(size_t bytes) @nogc nothrow pure @safe @trustedMake room for `bytes` more bytes in a single block (when the total is known in advance)
void release() @nogc nothrow pure @safe @trustedFree everything.
size_t allocated() @nogc nothrow pure @safe const @trustedThe bytes taken from the system (all the blocks, used or not)
Destructors
Nested Templates
Block
structBuffer(T)

A growable array for temporary data (malloc'd, GC in CTFE). If memory runs out, the items are not added and failed becomes true (and stays true): the owner checks it at the end of its work, as it checks the results of the Arena.

Fields
bool failedMemory ran out: some items were not added
Methods
void put(T x) @nogc nothrow pure @safe @trustedAppend an item
void put(scope const(T)[] xs) @nogc nothrow pure @safe @trustedAppend many items at once
inout(T)[] opSlice() @nogc nothrow pure @safe inoutThe items (a slice of the buffer: valid until the next `put`)
inout(T) opIndex(size_t i) ref @nogc nothrow pure @safe inoutThe item at index `i`
size_t length() @property @nogc nothrow pure @safe constNumber of items
bool empty() @property @nogc nothrow pure @safe constIs it empty?
void clear() @nogc nothrow pure @safeRemove all the items (the memory is kept)
void removeLast() @nogc nothrow pure @safeRemove the last item
void shrinkTo(size_t n) @nogc nothrow pure @safeKeep only the first `n` items
Destructors

Functions 2

fnvoid copyItems(T)(T * dst, const(T) * src, size_t n) @nogc nothrow pure @safe @systemCopy `n` items (memcpy, a loop in CTFE)
fnvoid copyItems(T)(T * dst, T * src, size_t n) @nogc nothrow pure @safe @systemditto, from mutable items (CTFE can't cast away the const of a pointer)