GC分析是否有效?

时间:2017-10-03 09:06:15

标签: profiling d

如果我像这样dmd -profile=gc test.d编译这个程序并运行它: -

import std.stdio;

void add(ref int[] data)
{
    data ~= 1;
    data ~= 2;
}

void main()
{
    int[] a;
    a.reserve(1000);
    a.add();
    writeln(a);
}

然后我得到这样的profilegc.log: -

bytes allocated, allocations, type, function, file:line
              4               1 int[] test.add test.d:5
              4               1 int[] test.add test.d:6

我希望reserve调用会分配GC内存,而第5行和第6行不会分配任何内存,因为内存已经在数组中保留了。

所以: -

  1. 我对.reserve的理解是错误的。

  2. 分析器的结果不正确。

  3. 保留

  4. 时出现问题

    这些中的一个或多个是真的吗? (我希望能够做一个保留,以保证分配只发生在我想要的时间,并且分析器不会向我保证这是有效的...)

0 个答案:

没有答案
相关问题