Skip to content

Manual Memory Management

Timur Gafarov edited this page Feb 21, 2019 · 12 revisions

Manual Memory Management

Note: there is more informative article on dlib memory management tools - Best-Practices. You may want to check it out as well.

From version 0.5.0, dlib supports manual memory management (MMM) based on standard C malloc/free. You can use the module dlib.core.memory to allocate classes, structs and arrays in unmanaged heap using New and Delete template functions:

import dlib.core.memory;

class MyClass 
{
    int x;

    this(int x)
    {
        this.x = x;
    }
}

MyClass obj = New!MyClass(99);
assert(obj.x == 99);
Delete(obj);

int[] arr = New!(int[])(100);
assert(arr.length == 100);
Delete(arr);
Clone this wiki locally