Search code examples
memory-managementdallocation

How can i free all the items of a FreeList?


SharedFreeList has the right method but I don't see how to free all the nodes of a FreeList:

module runnable;

import std.experimental.allocator.building_blocks;
import std.experimental.allocator.mallocator;
import std.experimental.allocator;

shared SharedFreeList!(Mallocator, 0, unbounded) heap1;
FreeList!(Mallocator, 0, unbounded) heap2;

shared static ~this()
{
    heap1.deallocateAll; // OK
}

static ~this()
{
    heap2.deallocateAll; // no prop deallocateAll for...
}

While this example is pointless, I may want to do the same in a class destructor. With certain static parameters, FreeList.deallocateAll seems to be deactivated, however there must be a way to deallocate all the nodes in the list, right ?


Solution

  • according DOC:

    Defined only if ParentAllocator defines deallocateAll. If so, forwards to it and resets the freelist.

    You use Mallocator which does not have deallocateAll so you can't use it. But SharedFreeList has own implementation of deallocateAll.

    So I would probably create an issue on https://issues.dlang.org. Because I belive same method could be implement for FreeList too.