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
Replaces the global memory context for the current scope with the given allocator.
MemoryContext _previousMemoryContextA dynamic string of chars backed by external memory.
A dynamic array.
true isBasicContainerfalse isBufferContainerfalse hasFixedCapacityT[] itemsSz capacityMemoryContext capturebool canIgnoreLeakT * ptr()bool isEmpty()bool appendBlank(IStr file = __FILE__, Sz line = __LINE__) @trustedbool append(const(T)[] args...) @trustedbool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(T)[] args = []...) @trustedvoid removeShift(Sz i) @nogcvoid popFront() @nogcbool resizeBlank(Sz newLength, IStr file = __FILE__, Sz line = __LINE__) @trustedvoid clear() @nogcvoid ignoreLeak() @nogcT[] opIndex()T[] opIndex(T[] slice)void opIndexAssign(const(T) rhs, Sz i)void opIndexOpAssign(const(char)[] op)(const(T) rhs, Sz i)this(MemoryContext capture, const(T)[] args...)this(ref GrowingArena arena, const(T)[] args...)this(const(T)[] args...)A dynamic array that uses external memory provided at runtime.
bool growCapacity(C)(ref C arena)bool resizeCapacity(C)(ref C arena, Sz newCapacity) @trustedT[] items()T * ptr()bool isEmpty()bool appendBlank(IStr file = __FILE__, Sz line = __LINE__) @trustedbool append(const(T)[] args...) @trustedbool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(T)[] args = []...) @trustedvoid removeShift(Sz i)void pop()void popFront()void resizeBlank(Sz newLength, IStr file = __FILE__, Sz line = __LINE__)void fill(const(T) value) @trustedvoid clear()void ignoreLeak()void capture(MemoryContext value)T[] opIndex()T[] opIndex(T[] slice)void opIndexAssign(const(T) rhs, Sz i)void opIndexOpAssign(const(char)[] op)(const(T) rhs, Sz i)this(T[] data, const(T)[] args...)A dynamic array allocated on the stack.
true isBasicContainerfalse isBufferContainertrue hasFixedCapacityStaticArray!(T, N) dataSz lengthN capacityT[] items()T * ptr()bool isEmpty()bool appendBlank(IStr file = __FILE__, Sz line = __LINE__) @trustedbool append(const(T)[] args...) @trustedbool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(T)[] args = []...) @trustedvoid removeShift(Sz i)void pop()void popFront()void resizeBlank(Sz newLength, IStr file = __FILE__, Sz line = __LINE__)void fill(const(T) value) @trustedvoid clear()void ignoreLeak()void capture(MemoryContext value)T[] opIndex()T[] opIndex(T[] slice)void opIndexAssign(const(T) rhs, Sz i)void opIndexOpAssign(const(char)[] op)(const(T) rhs, Sz i)this(const(T)[] args...)An item of a sparse array.
A dynamic sparse array.
false isBasicContainerfalse isBufferContainerD.hasFixedCapacity hasFixedCapacityD dataSz hotIndexSz openIndexSz lengthbool isEmpty() @nogcbool append(const(T)[] args...) @trustedbool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(T)[] args = []...) @trustedvoid clear() @nogcvoid ignoreLeak() @nogc@nogc auto ids()@nogc auto items()void opIndexAssign(const(T) rhs, Sz i)void opIndexOpAssign(IStr op)(const(T) rhs, Sz i)this(MemoryContext capture, const(T)[] args...)this(ref GrowingArena arena, const(T)[] args...)this(const(T)[] args...)A dynamic generational array.
false isBasicContainerfalse isBufferContainerD.hasFixedCapacity hasFixedCapacityD dataG generationsbool isEmpty() @nogcvoid clear() @nogcvoid ignoreLeak() @nogc@nogc auto ids()@nogc auto items()void opIndexAssign(const(T) rhs, GenIndex i)void opIndexOpAssign(IStr op)(const(T) rhs, GenIndex i)A dynamic bit array.
false isBasicContainerfalse isBufferContainerD.hasFixedCapacity hasFixedCapacityD bucketsSz lengthcast(Item) 0 zerocast(Item) 1 onecast(Sz) (Item.sizeof * 8) bucketCapacitybucketCapacity - 1 bucketIndexMask/* computed */ bucketShiftAmountbool isEmpty()bool append(const(bool)[] args...)bool appendSource(IStr file = __FILE__, Sz line = __LINE__, const(bool)[] args = []...)void removeShift(Sz i) @nogcvoid pop() @nogcvoid popFront() @nogcvoid fill(const(bool) value) @nogcvoid ignoreLeak() @nogcvoid opIndexAssign(const(bool) rhs, Sz i)The common bit array type.
A dynamic 2D array.
false isBasicContainerfalse isBufferContainerD.hasFixedCapacity hasFixedCapacityD tilesSz rowCountSz colCountT * ptr()bool isEmpty()T[] opIndex()void opIndexAssign(T rhs, Sz row, Sz col)void opIndexOpAssign(IStr op)(T rhs, Sz row, Sz col)void resizeBlank(Sz newRowCount, Sz newColCount, IStr file = __FILE__, Sz line = __LINE__)void fill(T value) @nogcvoid clear() @nogcvoid ignoreLeak() @nogcA static arena allocator.
ubyte * dataSz capacitySz offsetSz checkpointOffsetSz previousOffsetvoid * lastPtrArena * nextvoid ready(ubyte[] newData)void * realloc(Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file = __FILE__, Sz line = __LINE__)T[] makeSliceBlank(T)(Sz length, 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 dropCheckpoint()void clear()A dynamic arena allocator.
void * realloc(Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file = __FILE__, Sz line = __LINE__)T[] makeSliceBlank(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)T[] resizeSlice(T)(T * values, Sz oldLength, Sz newLength, IStr file = __FILE__, Sz line = __LINE__)void clear()void * realloc(Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file = __FILE__, Sz line = __LINE__)T[] makeSliceBlank(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)T[] resizeSlice(T)(T * values, Sz oldLength, Sz newLength, IStr file = __FILE__, Sz line = __LINE__)this(ref T data)Functions 63
ScopedMemoryContext ScopedDefaultMemoryContext() @safe nothrow @nogcReplaces the global memory context for the current scope with the default allocator.void * jokaSystemReallocWrapper(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line)A realloc wrapper that uses the system allocator.void * jokaRealloc(void * ptr, Sz size, Sz oldSize = 0, IStr file = __FILE__, Sz line = __LINE__)Reallocates a block of memory.void jokaFree(void * ptr, Sz oldSize = 0, IStr file = __FILE__, Sz line = __LINE__)Frees a block of memory.T * jokaMakeBlank(T)(IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value without initializing it.T * jokaMakeBlank(T)(MemoryContext context, IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value without initializing it.T * jokaMake(T)(IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value and initializes it.T * jokaMake(T)(MemoryContext context, IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value and initializes it.T * jokaMake(T)(const(T) value, IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value and initializes it.T * jokaMake(T)(MemoryContext context, const(T) value, IStr file = __FILE__, Sz line = __LINE__)Allocates memory for a value and initializes it.T[] jokaMakeSliceBlank(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice without initializing its elements.T[] jokaMakeSliceBlank(T)(MemoryContext context, Sz length, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice without initializing its elements.T[] jokaMakeSlice(T)(Sz length, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.T[] jokaMakeSlice(T)(MemoryContext context, Sz length, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.T[] jokaMakeSlice(T)(Sz length, const(T) value, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.T[] jokaMakeSlice(T)(MemoryContext context, Sz length, const(T) value, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.T[] jokaMakeSlice(T)(const(T)[] values, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.T[] jokaMakeSlice(T)(MemoryContext context, const(T)[] values, IStr file = __FILE__, Sz line = __LINE__)Allocates a slice and initializes its elements.T[] jokaResizeSlice(T)(T * values, Sz length, Sz oldLength = 0, IStr file = __FILE__, Sz line = __LINE__)Resizes a slice, with the previous pointer getting freed.T[] 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.T 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.T 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.T 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.T 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.void * nullAllocatorReallocWrapper(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line)A realloc wrapper that always returns null.void jokaRestoreNullAllocatorSetup(ref MemoryContext context)Configures a memory context to use the null allocator.void jokaRestoreDefaultAllocatorSetup(ref MemoryContext context)Configures a memory context to use the default allocator.void jokaEnsureCapture(ref MemoryContext capture)Sets a memory context to the global context if it has no realloc function.Sz beginAllocationGroup(IStr group) @trustedBegins a new allocation group for the memory tracker and returns the current group depth.Sz endAllocationGroup() @trusted @nogcEnds the current allocation group for the memory tracker and returns the current group depth.IStr memoryTrackingInfo(IStr pathFilter = "", bool canShowEmpty = false) @trusted nothrowReturns a summary of memory leaks and invalid frees detected by the memory tracker.void * arenaAllocatorReallocWrapper(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line) @trusted @nogcvoid * growingArenaAllocatorReallocWrapper(void * allocatorState, Sz alignment, void * oldPtr, Sz oldSize, Sz newSize, IStr file, Sz line) @trustedSz findListCapacity(Sz length, Sz currentCapacity = 0)Sz findListCapacityFastAndAssumeOneAddedItemInLength(Sz length, Sz currentCapacity = 0)Sz findGridIndex(Sz row, Sz col, Sz colCount)Sz findGridRow(Sz gridIndex, Sz colCount)Sz findGridCol(Sz gridIndex, Sz colCount)IStr 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...IStr 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...IStr 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.IStr 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.IStr 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.IStr 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.void sprintln(S = LStr, A...)(ref S buffer, A args)Prints text with a new line at the end to the given buffer.void 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.void 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.bool isContainerType(T)()bool isBasicContainerType(T)()bool isBufferContainerType(T)()bool isFixedContainerType(T)()bool isSparseContainerPartsValid(T, D)()bool isGenContainerPartsValid(T, D, G)()bool isLStrType(T)()bool isBStrType(T)()bool isFStrType(T)()bool isStrContainerType(T)()Variables 3
MemoryContext __memoryContextdefaultJokaMemoryAlignment = 16defaultListCapacity = 8The default list capacity. It is also the smallest list capacity.