The GC allocates in chunks that are a power of 2. This causes a lot of memory wasted:
module waste;
import core.memory;
struct S
{
char[129] data;
}
void main()
{
GC.disable();
foreach (_; 0 .. 1000000)
new S;
}
compile and run with
>waste.exe --DRT-gcopt=profile:1
Number of collections: 2
Total GC prep time: 0 milliseconds
Total mark time: 0 milliseconds
Total sweep time: 8 milliseconds
Total page recovery time: 3 milliseconds
Max Pause Time: 0 milliseconds
Grand total GC time: 12 milliseconds
GC summary: 247 MB, 2 GC 12 ms, Pauses 0 ms < 0 ms
=> even though only 129 MB are allocated, the GC needs 247 MB. With a struct size of 128, it needs 145 MB.