OK to do bit-packing with GC pointers?

Ben Jones fake at fake.fake
Fri Jul 22 18:34:18 UTC 2022


On Friday, 22 July 2022 at 16:57:21 UTC, Steven Schveighoffer 
wrote:
>
> It's specifically undefined behavior by the spec, but in 
> practice, I think it will work, as long as the block you have 
> isn't marked as not allowing interior pointers.
>
> See: https://dlang.org/spec/garbage.html#pointers_and_gc
>
> Specifically "Do not take advantage of alignment of pointers to 
> store bit flags in the low order bits"
>
> -Steve

Can you elaborate on why it's probably OK in practice?

I guess the alternative to is to to make them structs instead of 
classes and manually alloc/free them (or keep them as classes, 
but still avoid the GC)?

Seems like std.bitmanip.taggedClassRef should have a big warning 
on it, right?

Thanks


More information about the Digitalmars-d-learn mailing list