Idea #1 on integrating RC with GC

Adam D. Ruppe destructionator at gmail.com
Wed Feb 5 15:16:52 PST 2014


On Wednesday, 5 February 2014 at 22:32:52 UTC, Andrei 
Alexandrescu wrote:
> On the face of it it seems odd that reference counted chunks of 
> typed memory are deemed useless

I don't think anybody has actually said that. They have their 
places, it is just useless to talk about throwing them in 
everywhere.

> I should also add that imparting useful semantics to scope is 
> much more difficult than it might seem.

I'm not so sure about that*, but the fact is scope would be 
enormously useful if it was implemented.

* Let's say it meant "assigning to any higher scope is 
prohibited". That should be trivially easy to check and ensures 
that variable itself doesn't escape. The tricky part would be 
preventing:

int[] global;
void foo(scope int[] a) {
    int[] b = a;
    global = b;
}


And that's easy to fix too: make ALL variables scope, unless 
specifically marked otherwise at the type declaration site (or if 
they are value types OR references to immutable data, which are 
very similar to value types in use).

The type declaration can be marked as a reference encapsulation 
and those are allowed to be passed up (if the type otherwise 
allows; e.g. postblit is not disabled).

That would break a fair chunk of existing code**, but it'd make 
memory management explicit, correct, and user extensible.

** I think moving to not null by default at the same time would 
be good, just rip off teh whole band aid.


More information about the Digitalmars-d mailing list