Module scid.core.memory

Memory management. The code in this module is borrowed from David Simcha's dstats project, specifically the dstats.alloc module.

Functions

NameDescription
appendDelOld(to, from) Appends to an array, deleting the old array if it has to be realloced.
exit()
fprintf(, )
lengthVoid(input, newLength)
lengthVoid(input, newLength) Lengthens an array w/o initializing new elements.
newStack(size, state) Allocates an array of type T and size size using TempAlloc. Note that appending to this array using the ~= operator, or enlarging it using the .length property, will result in undefined behavior. This is because, if the array is located at the beginning of a TempAlloc block, the GC will think the capacity is as large as a TempAlloc block, and will overwrite adjacent TempAlloc-allocated data, instead of reallocating it.
newVoid(length) Returns a new array of type T w/o initializing elements.
rangeCopy(to, from)
reserve(input, newLength)
reserve(input, newLength) Reserves more space for an array w/o changing its length or initializing the space.
stackCat(data) **Same as newStack(size_t) but uses stateCopy cached on stack by caller
tempdup(data) Creates a duplicate of a range for temporary use within a function in the best wsy that can be done safely. If ElementType!(T) is a value type or T is an array, the results can safely be placed in TempAlloc because either it doesn't need to be scanned by the GC or there's guaranteed to be another reference to the contents somewhere. Otherwise, the results are placed on the GC heap.
tempdup(data)
toArray(range) Converts any range to an array on the GC heap by the most efficient means available. If it is already an array, duplicates the range.

Structs

NameDescription
TempAlloc A struct to allocate memory in a strictly first-in last-out order for things like scratch space. Technically, memory can safely escape the scope in which it was allocated. However, this is a very bad idea unless being done within the private API of a class, struct or nested function, where it can be guaranteed that LIFO will not be violated.

Templates

NameDescription
blockAttribute
isReferenceType
IsType

Manifest constants

NameTypeDescription
hasLength

Global variables

NameTypeDescription
newFrame immutable(char[]) A string to mixin at the beginning of a scope, purely for convenience. Initializes a TempAlloc frame using frameInit(), and inserts a scope statement to delete this frame at the end of the current scope.

Aliases

NameTypeDescription
ArrayType1 T