The "no gc" crowd

Michel Fortin michel.fortin at michelf.ca
Wed Oct 9 07:36:36 PDT 2013


On 2013-10-09 14:06:51 +0000, Johannes Pfau <nospam at example.com> said:

> 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.

The problem is that you can't cast Y to its base class Object (because 
you'd be casting an ARC pointer to a GC one and the reference count 
would not be maintained). Even calling Object's functions should be 
prohibited (because the "this" pointer is a GC pointer inside of 
Object's functions, and it could be leaked). So, de facto, by 
introducing all the necessary safety limitations, you've practically 
made Y a root class. The only things you can safely access from the 
base non-ref-counted class are its variables and its static functions.

And the same apply to interface: you can't mix them.

On top of that all that, if your goal is to go GC-free, you have to 
reinvent the whole standard library (so it uses ref-counted classes) 
and you still have to avoid the common pitfalls of implicit allocations 
(array concat for instance). So it's not terribly useful for someone 
whose goal is to avoid the GC.

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list