-
-
Notifications
You must be signed in to change notification settings - Fork 32
dlib.core.memory
Timur Gafarov edited this page Apr 26, 2017
·
2 revisions
Global GC-free instantiator for classes, structs and arrays. It utilizes dlib.memory for actual memory allocation, so it is possible to switch allocator that is being used. By default, dlib.memory.mallocator.Mallocator is used.
-
T New(T, A...)(A args)- creates an object of type T and calls its constructor if necessary. This is an equivalent for D'snewopetator.argsis an arguments tuple that is passed to constructor. -
void Delete(T)(T obj)- destroys an object of type T previously created byNewand calls its destructor if necessary. -
ulong allocatedMemory()- returns current amount of allocated memory in bytes. This is 0 at program start. -
Allocator globalAllocator()- returns currentAllocatorthat is used byNewandDelete. -
void globalAllocator(Allocator a)- sets allocator that should be used byNewandDelete.
MyClass c = New!MyClass(10, 4, 5);
int[] arr = New!(int[])(100);
assert(arr.length == 100);
MyStruct* s = New!MyStruct;
Delete(c);
Delete(arr);
Delete(s);The module includes a simple memory profiler that can be turned on with MemoryDebug version switch. If active, it will store information about every allocation (type and size), and will mark those which are leaked (haven't been deleted).
-
printMemoryLog()- prints an allocation list. Does nothing if compiled withoutMemoryDebugoption.