What's the go with the GC these days?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jan 7 19:46:58 UTC 2019


On Mon, Jan 07, 2019 at 08:31:06PM +0100, Jacob Carlborg via Digitalmars-d wrote:
> On 2019-01-06 04:42, Walter Bright wrote:
[...]
> > Andrei, Razvan, and I have decided that the most pragmatic way
> > forward to support reference counting is to support copy
> > constructors ala C++.  C++ is clearly successful with this approach,
> > and Andrei/Razvan concluded that D's postblit just doesn't cut it.
> > Razvan has a proposal for copy constructors, and an implementation
> > PR that has fallen a bit behind his latest proposal.
> 
> Razvan has confirmed that copy constructors are only for structs [1].
> The ARC (opAddRef/opRelease) proposal was for classes as well. So copy
> constructors are not a substitute as defined now.
[...]

I think the idea is probably to use struct wrappers to implement RC,
i.e., you'd have a struct wrapping a class reference of the object it's
managing.  As long as the struct can have semantics compatible with RC,
it can be used to implement RC. At least in theory.

My suspicion, though, is that at some point further language support is
going to be needed, because of interaction with D's const system. The RC
count needs to be mutable, yet the managed object must be allowed to be
const or immutable in a way that doesn't require onerous, incomplete
workarounds (like using a Const template instead of just typing `const
RC!MyClass` -- which won't work if you have the RC'd object inside
another aggregate that also needs const/immutable qualifiers).

Requiring that RC objects can only be mutable is going to lead to more
dissatisfaction about RC in D.


T

-- 
The easy way is the wrong way, and the hard way is the stupid way. Pick one.


More information about the Digitalmars-d mailing list