Idea #1 on integrating RC with GC
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Feb 5 16:42:20 PST 2014
On 2/5/14, 3:16 PM, Adam D. Ruppe wrote:
> 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 think part of the problem is a disconnect in assumptions and
expectations. My idea was to simply make a first simple and obvious step
toward improving the situation. Apparently that wasn't quite understood
because ten people have eleven notions about what's desirable and even
possible with regard to alternate memory management schemes.
One school of thought seems to be that D should be everything it is
today, just with reference counting throughout instead of garbage
collection. One build flag to rule them all would choose one or the other.
One other school of thought (to which I subscribe) is that one should
take advantage of reference counting where appropriate within a GC
milieu, regardless of more radical RC approaches that may be available.
>> 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).
Yah, that does break a bunch of code. Things like the type of "this" in
class objects also comes to mind. Binding ref is also a related topic.
All of these are complex matters, and I think a few simple sketches
don't do them justice.
Andrei
More information about the Digitalmars-d
mailing list