unstd.memory.allocation

Manual memory management routines.

Warning: Never use functions like malloc directly unless you know what you are doing as unaligned memory which it returns may lead to random crashed, incorrect behaviour and/or performance reduction.

Also manual count * element size multiplication often leads to buffer overflow vulnerability as one forgets the check.

Members

Enums

isUnalignedAllocator
eponymoustemplate isUnalignedAllocator(A)

Returns true if A is an unaligned allocator.

Functions

allocate
T[] allocate(A allocator, size_t count, bool initialize, bool gcScan)

Requests a properly aligned block of memory of count * T.sizeof bytes from allocator.

free
void free(A allocator, T[] array, bool gcScan)

Deallocates the memory referenced by array.ptr from allocator and sets array to null.

free
void free(A allocator, T* ptr, bool gcScan)

Deallocates the memory referenced by ptr from allocator.

memoryAdd
size_t memoryAdd(size_t bytes1, size_t bytes2)
Undocumented in source.
memoryMult
size_t memoryMult(size_t elementSize, size_t count)
Undocumented in source.
rawAllocate
void* rawAllocate(A allocator, size_t alignment, size_t elementSize, size_t count, bool zeroFill, bool gcScan)

Requests an alignment-byte aligned block of memory of count * elementSize bytes from allocator.

rawFree
void rawFree(A allocator, size_t alignment, void* ptr, bool gcScan)

Deallocates the memory referenced by ptr from allocator.

rawReallocate
void rawReallocate(A allocator, size_t alignment, size_t elementSize, void* ptr, size_t preserveCount, size_t newCount, bool zeroFill, bool gcScan)

Requests resize of an alignment-byte aligned block of memory allocated from allocator or if ptr is null requests memory allocation like rawAllocate/tryRawAllocate. Memory may be moved, but preserveCount elements content will stay the same.

reallocate
void reallocate(A allocator, T[] array, size_t newCount, bool initialize, bool gcScan)

Requests resize of a properly aligned block of memory allocated from allocator or if ptr is null requests memory allocation like allocate/tryAllocate. Memory may be moved, but array elements content will stay the same.

tempAlloc
auto tempAlloc(size_t count, bool initialize)

Creates temporary buffer.

testAllocator
void testAllocator(A a)
Undocumented in source. Be warned that the author may not have intended to support it.
tryAllocate
T[] tryAllocate(A allocator, size_t count, bool initialize, bool gcScan)

Requests a properly aligned block of memory of count * T.sizeof bytes from allocator.

tryRawAllocate
void* tryRawAllocate(A allocator, size_t alignment, size_t elementSize, size_t count, bool zeroFill, bool gcScan)

Requests an alignment-byte aligned block of memory of count * elementSize bytes from allocator.

tryRawReallocate
bool tryRawReallocate(A allocator, size_t alignment, size_t elementSize, void* ptr, size_t preserveCount, size_t newCount, bool zeroFill, bool gcScan)

Requests resize of an alignment-byte aligned block of memory allocated from allocator or if ptr is null requests memory allocation like rawAllocate/tryRawAllocate. Memory may be moved, but preserveCount elements content will stay the same.

tryReallocate
bool tryReallocate(A allocator, T[] array, size_t newCount, bool initialize, bool gcScan)

Requests resize of a properly aligned block of memory allocated from allocator or if ptr is null requests memory allocation like allocate/tryAllocate. Memory may be moved, but array elements content will stay the same.

Properties

cHeap
CHeap cHeap [@property getter]

An unaligned allocator which uses C's malloc/free.

heap
ref heap [@property getter]

An unaligned shared allocator which can be safely used from multiple threads.

threadHeap
ref threadHeap [@property getter]

An unaligned thread local allocator.

Static variables

_cHeap
CHeap _cHeap;
Undocumented in source.

Structs

CHeap
struct CHeap
Undocumented in source.

Meta

Authors

Denis Shelomovskij