【问题标题】:How can i free all the items of a FreeList?如何释放 FreeList 的所有项目?
【发布时间】:2016-08-11 16:47:01
【问题描述】:

SharedFreeList 有正确的方法,但我不知道如何释放 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...
}

虽然这个例子没有意义,但我可能想在类析构函数中做同样的事情。使用某些静态参数,FreeList.deallocateAll 似乎被停用了,但是必须有一种方法可以释放列表中的所有节点,对吧?

【问题讨论】:

    标签: memory-management d allocation


    【解决方案1】:

    根据DOC

    仅当 ParentAllocator 定义 deallocateAll 时才定义。如果是,则转发给它并重置空闲列表。

    您使用Mallocator,它没有deallocateAll,所以您不能使用它。但是SharedFreeList 有自己的deallocateAll 实现。

    所以我可能会在https://issues.dlang.org 上创建一个问题。因为我相信同样的方法也可以用于FreeList

    【讨论】:

    • 我没有看过FreeList 的实现,但它可能只跟踪空闲对象,而不是任何已分配的对象。在这种情况下,将无法实现deallocateAll
    猜你喜欢
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 2021-10-26
    • 2018-08-27
    • 2018-07-02
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多