joka.memory

The memory module provides functions for dealing with memory and various general-purpose containers. List, BufferList, and FixedList are the "basic" containers. Most other containers can accept one of those to adjust their allocation strategy.

Types 22

Groups allocations under a name for tracking purposes.

Fields
IStr _currentAllocationGroup
Constructors
this(IStr group)
Destructors
deprecated Use `ScopedAllocationGroup`.

A dynamic allocator API.

Fields
void * allocatorState
Methods
void * malloc(Sz alignment, Sz size, IStr file, Sz line)Allocates a block of memory.
void * realloc(Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line)Reallocates a block of memory.
void free(Sz alignment, void * oldPtr, Sz oldSize, IStr file, Sz line)Frees a block of memory.
aliasAllocatorMallocFunc = void * function(void * allocatorState, Sz alignment, Sz size, IStr file, Sz line)
aliasAllocatorReallocFunc = void * function(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line)
aliasAllocatorFreeFunc = void function(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, IStr file, Sz line)

Replaces the global memory context for the current scope with the given allocator.

Fields
MemoryContext _previousMemoryContext
Constructors
this(MemoryContext newContext)
this(ref Arena arena)
this(ref GrowingArena arena)
Destructors
aliasLStr = List!char

A dynamic string of chars.

aliasBStr = BufferList!char

A dynamic string of chars backed by external memory.

aliasFStr(Sz N) = FixedList!(char, N)

A dynamic string of chars allocated on the stack.

structList(T)

A dynamic array.

Fields
true isBasicContainer
false isBufferContainer
false hasFixedCapacity
T[] items
Sz capacity
bool canIgnoreLeak
Methods
T * ptr()
bool isEmpty()
bool appendBlank(IStr file = __FILE__, Sz line = __LINE__) @trusted
bool append(const(T)[] args...) @trusted
bool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(T)[] args = []...) @trusted
bool push(const(T) arg, IStr file = __FILE__, Sz line = __LINE__) @trusted
void remove(Sz i) @trusted @nogc
void removeShift(Sz i) @nogc
void pop() @trusted @nogc
void popFront() @nogc
bool reserve(Sz newCapacity, IStr file = __FILE__, Sz line = __LINE__) @trusted
bool resizeBlank(Sz newLength, IStr file = __FILE__, Sz line = __LINE__) @trusted
bool resize(Sz newLength, IStr file = __FILE__, Sz line = __LINE__)
void fill(const(T) value) @trusted @nogc
void clear() @nogc
void free(IStr file = __FILE__, Sz line = __LINE__) @trusted
void ignoreLeak() @nogc
IStr toStr() @nogc
T[] opSlice(Sz dim)(Sz i, Sz j)
T[] opIndex()
T[] opIndex(T[] slice)
T opIndex(Sz i) ref
void opIndexAssign(const(T) rhs, Sz i)
void opIndexOpAssign(const(char)[] op)(const(T) rhs, Sz i)
Sz opDollar(Sz dim)()
Constructors
this(MemoryContext capture, const(T)[] args...)
this(ref Arena arena, const(T)[] args...)
this(ref GrowingArena arena, const(T)[] args...)
this(const(T)[] args...)
structBufferList(T)

A dynamic array that uses external memory provided at runtime.

Fields
true isBasicContainer
true isBufferContainer
true hasFixedCapacity
T[] data
Sz length
Methods
bool growCapacity(C)(ref C arena)
bool resizeCapacity(C)(ref C arena, Sz newCapacity) @trusted
bool resizeCapacity(T[] newRawPureData) @trusted nothrow @nogc
T[] items()
T * ptr()
bool isEmpty()
bool appendBlank(IStr file = __FILE__, Sz line = __LINE__) @trusted
bool append(const(T)[] args...) @trusted
bool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(T)[] args = []...) @trusted
bool push(const(T) arg, IStr file = __FILE__, Sz line = __LINE__) @trusted
void remove(Sz i) @trusted
void removeShift(Sz i)
void pop()
void popFront()
void reserve(Sz newCapacity, IStr file = __FILE__, Sz line = __LINE__)
void resizeBlank(Sz newLength, IStr file = __FILE__, Sz line = __LINE__)
void resize(Sz newLength, IStr file = __FILE__, Sz line = __LINE__)
void fill(const(T) value) @trusted
void clear()
void free(IStr file = __FILE__, Sz line = __LINE__)
void ignoreLeak()
T[] opSlice(Sz dim)(Sz i, Sz j)
T[] opIndex()
T[] opIndex(T[] slice)
T opIndex(Sz i) ref
void opIndexAssign(const(T) rhs, Sz i)
void opIndexOpAssign(const(char)[] op)(const(T) rhs, Sz i)
Sz opDollar(Sz dim)()
Constructors
this(T[] data, const(T)[] args...)
structFixedList(T, Sz N)

A dynamic array allocated on the stack.

Fields
true isBasicContainer
false isBufferContainer
true hasFixedCapacity
StaticArray!(T, N) data
Sz length
N capacity
Methods
T[] items()
T * ptr()
bool isEmpty()
bool appendBlank(IStr file = __FILE__, Sz line = __LINE__) @trusted
bool append(const(T)[] args...) @trusted
bool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(T)[] args = []...) @trusted
bool push(const(T) arg, IStr file = __FILE__, Sz line = __LINE__) @trusted
void remove(Sz i) @trusted
void removeShift(Sz i)
void pop()
void popFront()
void reserve(Sz newCapacity, IStr file = __FILE__, Sz line = __LINE__)
void resizeBlank(Sz newLength, IStr file = __FILE__, Sz line = __LINE__)
void resize(Sz newLength, IStr file = __FILE__, Sz line = __LINE__)
void fill(const(T) value) @trusted
void clear()
void free(IStr file = __FILE__, Sz line = __LINE__)
void ignoreLeak()
T[] opSlice(Sz dim)(Sz i, Sz j)
T[] opIndex()
T[] opIndex(T[] slice)
T opIndex(Sz i) ref
void opIndexAssign(const(T) rhs, Sz i)
void opIndexOpAssign(const(char)[] op)(const(T) rhs, Sz i)
Sz opDollar(Sz dim)()
Constructors
this(const(T)[] args...)

An item of a sparse array.

Fields
Item value
bool flag
structSparseList(T, D = List!(SparseListItem!T)) if (isSparseContainerPartsValid!(T, D))

A dynamic sparse array.

Fields
false isBasicContainer
false isBufferContainer
D.hasFixedCapacity hasFixedCapacity
D data
Sz hotIndex
Sz openIndex
Sz length
Methods
Sz capacity() @nogc
bool isEmpty() @nogc
bool has(Sz i) @nogc
T hotItem() @nogc ref
bool append(const(T)[] args...) @trusted
bool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(T)[] args = []...) @trusted
bool push(const(T) arg, IStr file = __FILE__, Sz line = __LINE__) @trusted
void remove(Sz i) @nogc
void reserve(Sz capacity, IStr file = __FILE__, Sz line = __LINE__)
void clear() @nogc
void free(IStr file = __FILE__, Sz line = __LINE__)
void ignoreLeak() @nogc
@nogc auto ids()
@nogc auto items()
T opIndex(Sz i) ref
void opIndexAssign(const(T) rhs, Sz i)
void opIndexOpAssign(IStr op)(const(T) rhs, Sz i)
Constructors
this(MemoryContext capture, const(T)[] args...)
this(ref Arena arena, const(T)[] args...)
this(ref GrowingArena arena, const(T)[] args...)
this(const(T)[] args...)
structGenList(T, D = SparseList!T, G = List!Gen) if (isGenContainerPartsValid!(T, D, G))

A dynamic generational array.

Fields
false isBasicContainer
false isBufferContainer
D.hasFixedCapacity hasFixedCapacity
D data
G generations
Methods
Sz length() @nogc
Sz capacity() @nogc
bool isEmpty() @nogc
bool has(GenIndex i) @nogc
GenIndex append(const(T) arg, IStr file = __FILE__, Sz line = __LINE__)
void remove(GenIndex i) @nogc
void reserve(Sz capacity, IStr file = __FILE__, Sz line = __LINE__)
void clear() @nogc
void free(IStr file = __FILE__, Sz line = __LINE__)
void ignoreLeak() @nogc
@nogc auto ids()
@nogc auto items()
T opIndex(GenIndex i) ref
void opIndexAssign(const(T) rhs, GenIndex i)
void opIndexOpAssign(IStr op)(const(T) rhs, GenIndex i)
Constructors
this(ref Arena arena)
this(ref GrowingArena arena)
structGBitList(T, D = List!T) if (__traits(isUnsigned, T))

A dynamic bit array.

Fields
false isBasicContainer
false isBufferContainer
D.hasFixedCapacity hasFixedCapacity
D buckets
Sz length
cast(Item) 0 zero
cast(Item) 1 one
cast(Sz) (Item.sizeof * 8) bucketCapacity
bucketCapacity - 1 bucketIndexMask
/* computed */ bucketShiftAmount
Methods
bool isEmpty()
bool append(const(bool)[] args...)
bool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(bool)[] args = []...)
bool push(const(bool) arg, IStr file = __FILE__, Sz line = __LINE__)
void remove(Sz i) @nogc
void removeShift(Sz i) @nogc
void pop() @nogc
void popFront() @nogc
bool reserve(Sz newCapacity, IStr file = __FILE__, Sz line = __LINE__)
void fill(const(bool) value) @nogc
void clear() @trusted @nogc
void free(IStr file = __FILE__, Sz line = __LINE__)
void ignoreLeak() @nogc
bool opIndex(Sz i)
void opIndexAssign(const(bool) rhs, Sz i)
Constructors
this(ref Arena arena)
this(ref GrowingArena arena)

The common bit array type.

structGrid(T, D = List!T) if (isBasicContainerType!D)

A dynamic 2D array.

Fields
false isBasicContainer
false isBufferContainer
D.hasFixedCapacity hasFixedCapacity
D tiles
Sz rowCount
Sz colCount
Methods
T * ptr()
bool has(Sz row, Sz col)
bool isEmpty()
T[] opIndex()
T opIndex(Sz row, Sz col) ref
void opIndexAssign(T rhs, Sz row, Sz col)
void opIndexOpAssign(IStr op)(T rhs, Sz row, Sz col)
Sz opDollar(Sz dim)()
void reserve(Sz newCapacity, IStr file = __FILE__, Sz line = __LINE__)
void resizeBlank(Sz newRowCount, Sz newColCount, IStr file = __FILE__, Sz line = __LINE__)
void resize(Sz newRowCount, Sz newColCount, IStr file = __FILE__, Sz line = __LINE__)
void fill(T value) @nogc
void clear() @nogc
void free(IStr file = __FILE__, Sz line = __LINE__)
void ignoreLeak() @nogc
Constructors
this(ref Arena arena)
this(ref GrowingArena arena)
this(Sz rowCount, Sz colCount, T value = T.init, IStr file = __FILE__, Sz line = __LINE__)
this(MemoryContext capture, Sz rowCount, Sz colCount, T value = T.init, IStr file = __FILE__, Sz line = __LINE__)
structArena

A static arena allocator.

Fields
ubyte * data
Sz capacity
Sz offset
Sz checkpointOffset
Sz previousOffset
void * lastPtr
Arena * next
Methods
void ready(ubyte * newData, Sz newCapacity)
void ready(ubyte[] newData)
void * malloc(Sz alignment, Sz size, IStr file = __FILE__, Sz line = __LINE__)
void * realloc(Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file = __FILE__, Sz line = __LINE__)
T * makeBlank(T)(IStr file = __FILE__, Sz line = __LINE__)
T * make(T)(IStr file = __FILE__, Sz line = __LINE__)
T * make(T)(const(T) value, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSliceBlank(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSlice(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSlice(T)(Sz length, const(T) value, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSlice(T)(const(T)[] values, IStr file = __FILE__, Sz line = __LINE__)
T[] resizeSlice(T)(T * values, Sz oldLength, Sz newLength, IStr file = __FILE__, Sz line = __LINE__)
void checkpoint()
void rollback()
void rollback(Sz value)
void clear()
void reset(IStr file = __FILE__, Sz line = __LINE__)
Constructors
this(ubyte * data, Sz capacity)
this(ubyte[] data)

A dynamic arena allocator.

Fields
Arena * head
Arena * current
Sz chunkCapacity
Methods
void ready(Sz newChunkCapacity, IStr file = __FILE__, Sz line = __LINE__)
void * malloc(Sz alignment, Sz size, IStr file = __FILE__, Sz line = __LINE__)
void * realloc(Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file = __FILE__, Sz line = __LINE__)
T * makeBlank(T)(IStr file = __FILE__, Sz line = __LINE__)
T * make(T)(IStr file = __FILE__, Sz line = __LINE__)
T * make(T)(const(T) value, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSliceBlank(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSlice(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSlice(T)(Sz length, const(T) value, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSlice(T)(const(T)[] values, IStr file = __FILE__, Sz line = __LINE__)
T[] resizeSlice(T)(T * values, Sz oldLength, Sz newLength, IStr file = __FILE__, Sz line = __LINE__)
void free(IStr file = __FILE__, Sz line = __LINE__)
void clear()
Constructors
this(Sz chunkCapacity, IStr file = __FILE__, Sz line = __LINE__)
struct_ScopedArena(T)
Fields
T * _currentArena
Sz _currentArenaCheckpointOffset
Methods
void * malloc(Sz alignment, Sz size, IStr file = __FILE__, Sz line = __LINE__)
void * realloc(Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file = __FILE__, Sz line = __LINE__)
T * makeBlank(T)(IStr file = __FILE__, Sz line = __LINE__)
T * make(T)(IStr file = __FILE__, Sz line = __LINE__)
T * make(T)(const(T) value, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSliceBlank(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSlice(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)
T[] makeSlice(T)(Sz length, const(T) value, IStr file = __FILE__, Sz line = __LINE__)
T[] resizeSlice(T)(T * values, Sz oldLength, Sz newLength, IStr file = __FILE__, Sz line = __LINE__)
Constructors
this(ref T data)
Destructors

Functions 63

fnScopedMemoryContext ScopedDefaultMemoryContext() @safe nothrow @nogcReplaces the global memory context for the current scope with the default allocator.
fnvoid * jokaSystemReallocWrapper(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line)A realloc wrapper that uses the system allocator.
fnvoid * jokaMalloc(Sz size, IStr file = __FILE__, Sz line = __LINE__)Allocates a block of memory.
fnvoid * jokaRealloc(void * ptr, Sz size, Sz oldSize = 0, IStr file = __FILE__, Sz line = __LINE__)Reallocates a block of memory.
fnvoid jokaFree(void * ptr, Sz oldSize = 0, IStr file = __FILE__, Sz line = __LINE__)Frees a block of memory.
fnT * jokaMakeBlank(T)(IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value without initializing it.
fnT * jokaMakeBlank(T)(MemoryContext context, IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value without initializing it.
fnT * jokaMake(T)(IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value and initializes it.
fnT * jokaMake(T)(MemoryContext context, IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value and initializes it.
fnT * jokaMake(T)(const(T) value, IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value and initializes it.
fnT * jokaMake(T)(MemoryContext context, const(T) value, IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value and initializes it.
fnT[] jokaMakeSliceBlank(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice without initializing its elements.
fnT[] jokaMakeSliceBlank(T)(MemoryContext context, Sz length, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice without initializing its elements.
fnT[] jokaMakeSlice(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.
fnT[] jokaMakeSlice(T)(MemoryContext context, Sz length, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.
fnT[] jokaMakeSlice(T)(Sz length, const(T) value, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.
fnT[] jokaMakeSlice(T)(MemoryContext context, Sz length, const(T) value, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.
fnT[] jokaMakeSlice(T)(const(T)[] values, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.
fnT[] jokaMakeSlice(T)(MemoryContext context, const(T)[] values, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.
fnT[] jokaResizeSlice(T)(T * values, Sz length, Sz oldLength = 0, IStr file = __FILE__, Sz line = __LINE__)Resizes a slice, with the previous pointer getting freed.
fnT[] jokaResizeSlice(T)(MemoryContext context, T * values, Sz length, Sz oldLength = 0, IStr file = __FILE__, Sz line = __LINE__)Resizes a slice, with the previous pointer getting freed.
fnT jokaMakeJointBlank(T)(Sz * outTotalBytes, Sz[] lengths...) if (is(T == struct))Allocates a struct's slice fields in a single contiguous block without initializing them. Free the entire block by freeing the first field's pointer.
fnT jokaMakeJointBlank(T)(MemoryContext context, Sz * outTotalBytes, Sz[] lengths...) if (is(T == struct))Allocates a struct's slice fields in a single contiguous block without initializing them. Free the entire block by freeing the first field's pointer.
fnT jokaMakeJoint(T)(Sz[] lengths...) if (is(T == struct))Allocates a struct's slice fields in a single contiguous block and initializes them to zero. Free the entire block by freeing the first field's pointer.
fnT jokaMakeJoint(T)(MemoryContext context, Sz[] lengths...) if (is(T == struct))Allocates a struct's slice fields in a single contiguous block and initializes them to zero. Free the entire block by freeing the first field's pointer.
fnvoid * nullAllocatorReallocWrapper(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line)A realloc wrapper that always returns null.
fnvoid jokaRestoreNullAllocatorSetup(ref MemoryContext context)Configures a memory context to use the null allocator.
fnvoid jokaRestoreDefaultAllocatorSetup(ref MemoryContext context)Configures a memory context to use the default allocator.
fnvoid jokaEnsureCapture(ref MemoryContext capture)Sets a memory context to the global context if it has no realloc function.
fnauto ignoreLeak(T)(T ptr)Marks an allocation as ignored by the memory tracker.
fnSz beginAllocationGroup(IStr group) @trustedBegins a new allocation group for the memory tracker and returns the current group depth.
fnSz endAllocationGroup() @trusted @nogcEnds the current allocation group for the memory tracker and returns the current group depth.
fnIStr memoryTrackingInfo(IStr pathFilter = "", bool canShowEmpty = false) @trusted nothrowReturns a summary of memory leaks and invalid frees detected by the memory tracker.
fn_ScopedArena!T ScopedArena(T)(ref T arena) @trustedA RAII helper for arenas.
fnvoid * arenaAllocatorReallocWrapper(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line) @trusted @nogc
fnvoid * growingArenaAllocatorReallocWrapper(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line) @trusted
fnIStr gridIndexErrorMessage(Sz row, Sz col) @trusted @nogc
fnIStr genIndexErrorMessage(Sz value, Sz generation) @trusted @nogc
fnSz findListCapacity(Sz length, Sz currentCapacity = 0)
fnSz findGridIndex(Sz row, Sz col, Sz colCount)
fnSz findGridRow(Sz gridIndex, Sz colCount)
fnSz findGridCol(Sz gridIndex, Sz colCount)
fnIStr fmtIntoList(bool canAppend = false, S = LStr, A...)(ref S list, IStr fmtStr, A args)Formats a string using a list and returns the resulting formatted string. The list is cleared before writing. For details on formatting behavior, see the `fmtIntoBufferWithStrs` function in the `as...
fnIStr fmtIntoList(bool canAppend = false, S = LStr, A...)(ref S list, InterpolationHeader header, A args, InterpolationFooter footer)Formats a string using a list and returns the resulting formatted string. The list is cleared before writing. For details on formatting behavior, see the `fmtIntoBufferWithStrs` function in the `as...
fnIStr sprintf(S = LStr, A...)(ref S buffer, IStr fmtStr, A args)Prints formatted text to the given buffer. For details on formatting, see the `fmtIntoBuffer` function.
fnIStr sprintf(S = LStr, A...)(ref S buffer, InterpolationHeader header, A args, InterpolationFooter footer)Prints formatted text to the given buffer. For details on formatting, see the `fmtIntoBuffer` function.
fnIStr sprintfln(S = LStr, A...)(ref S buffer, IStr fmtStr, A args)Prints formatted text with a new line at the end to the given buffer. For details on formatting, see the `fmtIntoBuffer` function.
fnIStr sprintfln(S = LStr, A...)(ref S buffer, InterpolationHeader header, A args, InterpolationFooter footer)Prints formatted text with a new line at the end to the given buffer. For details on formatting, see the `fmtIntoBuffer` function.
fnvoid sprint(S = LStr, A...)(ref S buffer, A args)Prints text to the given buffer.
fnvoid sprintln(S = LStr, A...)(ref S buffer, A args)Prints text with a new line at the end to the given buffer.
fnvoid freeOnlyItems(T)(ref T container, IStr file = __FILE__, Sz line = __LINE__)Frees only the items within the container without freeing the container itself. Calls `free` on each item, passing `file` and `line` if supported.
fnvoid freeWithItems(T)(ref T container, IStr file = __FILE__, Sz line = __LINE__)Frees all items within the container and then frees the container itself. Equivalent to calling `freeOnlyItems` followed by `free` on the container.
fnbool isContainerType(T)()
fnbool isGenContainerPartsValid(T, D, G)()
fnbool isLStrType(T)()
fnbool isBStrType(T)()
fnbool isFStrType(T)()
fnbool isStrContainerType(T)()

Variables 3

varMemoryContext __memoryContext
enumvardefaultJokaMemoryAlignment = 16
enumvardefaultListCapacity = 8

The default list capacity. It is also the smallest list capacity.