Are D classes proper reference types?

IGotD- nise at nise.com
Fri Jun 25 21:05:36 UTC 2021


On Friday, 25 June 2021 at 20:22:24 UTC, Ola Fosheim Grøstad 
wrote:
>
> Hm. Not sure if I follow, I think we are talking about stuffing 
> bits into the counter and not the address?

Then I misunderstood. If it's a counter it should be fine.

>
> But fat pointers are 16 bytes, so quite expensive.

Yes, that's a tradeoff but one I'm willing to take. I'm thinking 
even bigger managed pointers of perhaps 32 bytes which has more 
metadata like the allocated size. Managed languages in general 
have fat pointers which we see everywhere and it is not a big 
deal.

If you are littering pointers you perhaps should refactor your 
code, use an array if loads of objects of the same type. Another 
thing which I'm not that satisfied with D is that there is no 
built in method of expanding member classes into the host class 
like C++ which creates pointer littering and memory fragmentation.


More information about the Digitalmars-d-learn mailing list