On Saturday, 20 February 2021 at 18:43:53 UTC, Steven
Schveighoffer wrote:
Last I checked*, the GC uses pools of 16-byte, 32-byte,
64-byte, etc blocks.
That has changed [to reduce wastage]; the new bin sizes are here
and include sizes like 176 (11*16):
https://github.com/dlang/druntime/blob/728f1d9c3b7a37eba4d59ee2637fb924053cba6d/src/core/internal/gc/impl/conservative/gc.d#L1166
(not sure about stack alignment for scope instances)
This works with LDC at least. E.g., this:
class C
{
align(64) int[2] data;
}
void foo()
{
scope c = new C();
}
allocates 72 bytes aligned at a 64-bytes stack boundary. 72
bytes? :) Yes - vptr, monitor, then 48 padding bytes (for 64-bit
target...), then 8 `data` bytes with .offsetof of 64. [And
classes don't need tail padding, as you can't allocate arrays of
class *instances* directly in the language.]
Structs are generally better suited for alignment purposes, but
the same GC limitations apply when allocating them on the heap.