The "no gc" crowd

Johannes Pfau nospam at example.com
Wed Oct 9 07:06:51 PDT 2013


Am Wed, 9 Oct 2013 09:38:12 -0400
schrieb Michel Fortin <michel.fortin at michelf.ca>:

> 
> I think the only way to make that work sanely is to create
> another root object for ref-counted classes.
> 

The problem here is we need a way to know that type X is refcounted,
right? Couldn't we just use an attribute with the class or interface
declaration:

@refcounted interface X{};
@refcounted class Y {};
class X1 : X;
class Y1 : Y;

Now we know for sure that all these classes and SubClasses are
refcounted.

> Another idea was to make *everything* in D ref-counted. ARC simply 
> becomes another GC implementation. There can be no confusion between 
> what's ref-counted and what isn't (everything is). It's much simpler 
> really. But Walter isn't keen on the idea of having to call a
> function at every pointer assignment to keep the reference count up
> to date (for performance reasons), so that idea was rejected. This
> makes some sense, because unlike Objective-C ARC where only
> Objective-C object pointers are ref-counted, in D you'd have to do
> that with all pointers, and some will point to external data that
> does not need to be ref-counted at all.

The GC should be integrated with ARC types. A generic solution could be
allowing different allocators with ARC types:
auto a = new!Malloc RefCountedClass();
auto b = new!GC RefCountedClass();
auto c = new!Pool RefCountedClass();

This can be done by storing a hidden pointer to the free function in
every @refcounted class and the GC's free function is then just a no-op.


More information about the Digitalmars-d mailing list