Are D classes proper reference types?

IGotD- nise at nise.com
Fri Jun 25 17:56:48 UTC 2021


On Friday, 25 June 2021 at 17:37:13 UTC, IGotD- wrote:
>
> 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.

One thing I have found out over the years that if you want to 
have full versatility, have a pointer to your free function in 
your fat pointer. By having this you have generic method to free 
your object when it goes out of scope. You have the ability to 
use custom allocators and even change allocators on the fly. If 
you for some reason don't want to free your object automatically, 
just put zero in that field for example.


More information about the Digitalmars-d-learn mailing list