import std.stdio;
import core.memory;
void printGCStats()
{
auto sts = GC.stats();
writefln("\n==\nGC Stats\n");
writefln("GC.allocatedInCurrentThread = %s", sts.allocatedInCurrentThread);
writefln("GC.freeSize = %s", sts.freeSize);
writefln("GC.usedSize = %s\n==\n", sts.usedSize);
}
void printGCProfileStats()
{
auto psts = GC.profileStats();
writefln("\n==\nGC ProfileStats\n");
writefln("GC.numCollections = %s", psts.numCollections);
writefln("GC.totalCollectionTime = %s", psts.totalCollectionTime);
writefln("GC.totalPauseTime = %s", psts.totalPauseTime);
writefln("GC.maxPauseTime = %s", psts.maxPauseTime);
writefln("GC.maxCollectionTime = %s", psts.maxCollectionTime);
}
void main(string[] args)
{
int[] v = [1, 2];
int n = 1 << 30;
printGCStats();
printGCProfileStats();
for (int i = 0; i < n - 2; ++i)
{
v ~= i;
}
writefln("v len: %s cap: %s\n", v.length, v.capacity);
printGCStats();
printGCProfileStats();
GC.collect();
printGCStats();
printGCProfileStats();
}
Before collect()
==
GC Stats
GC.allocatedInCurrentThread = 7329336480
GC.freeSize = 690925360
GC.usedSize = 7528243408
==
==
GC ProfileStats
GC.numCollections = 12
GC.totalCollectionTime = 1 ms, 50 μs, and 5 hnsecs
GC.totalPauseTime = 901 μs and 8 hnsecs
GC.maxPauseTime = 352 μs and 2 hnsecs
GC.maxCollectionTime = 352 μs and 6 hnsecs
After collect()
==
GC Stats
GC.allocatedInCurrentThread = 7329336672
GC.freeSize = 3462635488
GC.usedSize = 4756533280
==
==
GC ProfileStats
GC.numCollections = 13
GC.totalCollectionTime = 1 ms, 154 μs, and 9 hnsecs
GC.totalPauseTime = 981 μs and 8 hnsecs
GC.maxPauseTime = 352 μs and 2 hnsecs
GC.maxCollectionTime = 352 μs and 6 hnsecs