Are D classes proper reference types?
kinke
noone at nowhere.com
Fri Jun 25 23:55:40 UTC 2021
On Friday, 25 June 2021 at 17:05:41 UTC, Ola Fosheim Grøstad
wrote:
> Yes, if you don't want to support weak pointers. I think you
> need two counters if you want to enable the usage of weak
> pointers.
I cannot imagine how weak pointers would work without an ugly
extra indirection layer. If we're on the same page, we're talking
about embedding the reference counter *directly* in the class
instance, and the class ref still pointing directly to the
instance.
Weak pointers aren't in the language, so I don't see why they
would matter here. I thought you were after replacing
GC-allocated class instances by a simple RC scheme.
> One reason to put it at a negative offset is that it makes it
> possible to make it fully compatible with shared_ptr.
In modern C++ code I've been looking at so far, shared_ptr was
used very rarely (and unique_ptr everywhere). AFAIK, the main
reason being poor performance due to the extra indirection of
shared_ptr. So replacing every D class ref by a
shared_ptr-analogon for interop reasons would seem very backwards
to me.
More information about the Digitalmars-d-learn
mailing list