Are D classes proper reference types?

IGotD- nise at nise.com
Fri Jun 25 17:37:13 UTC 2021


On Friday, 25 June 2021 at 07:17:20 UTC, kinke wrote:
> Wrt. manual non-heap allocations (stack/data segment/emplace 
> etc.), you could e.g. reserve the most significant bit of the 
> counter to denote such instances and prevent them from being 
> free'd (and possibly finalization/destruction too; this would 
> need some more thought I suppose).

You cannot use the most significant bit as it will not work with 
some 32-bit systems. Linux with a 3G kernel position for example. 
Better to use the least significant bit as all allocated memory 
is guaranteed to be aligned. Regardless this requires compiler 
support for masking off this bit.

Now where going into halfway fat pointer support. Then we can 
just use fat pointers instead and have full freedom.


More information about the Digitalmars-d-learn mailing list