On Friday, 5 February 2021 at 22:46:05 UTC, Bastiaan Veelo wrote:

?? Do you mean no collections happen? 32bit GC should just work.

No, it doesn't - this code fails on memory allocation and works fine with -m64 switch:


import std.stdio;
import core.memory : GC;

void main() {

    void usage() {
writefln("Usage: %.2f MiB / collected: %d", (cast(double) GC.stats.usedSize) / 1_048_576, GC.profileStats.numCollections);
    }

    void foo() {
        string[] s;

        scope (exit) {
            s.length = 0;
        }

        foreach (i; 0 .. 50_000_00) {
            s ~= "a";
        }
    }

    foreach (i; 0 .. uint.max) {
        writefln("Round: %d", i + 1);
        foo();
        GC.collect();
        usage();
    }
}

...
Round: 24
Usage: 1603.57 MiB / collected: 27
Round: 25
Usage: 1691.64 MiB / collected: 28
Round: 26
Usage: 1729.50 MiB / collected: 29
Round: 27

core.exception.OutOfMemoryError@src\core\exception.d(647): Memory allocation failed

Reply via email to