draft proposal for ref counting in D

Walter Bright newshound2 at digitalmars.com
Wed Oct 9 19:18:27 PDT 2013


Michel Fortin wrote:

Le 25-juin-2013 à 17:00, Walter Bright  a écrit :

 > If a class contains the following methods, in either itself or a base class, 
it is
 > an RC class:
 >
 >
 >    T AddRef();
 >    T Release();
 >
 > An RC class is like a regular D class with these additional semantics:
 >
 > 1. In @safe code, casting (implicit or explicit) to a base class that does not
 > have both AddRef() and Release() is an error.

I'm just realizing that this means @safe code cannot call any member function of 
the non-reference-counted base class. This would require an implicit conversion 
of "this" to the base class.

@system code could, but it'd be extremely uneasy doing such calls unless I am 
the one in charge of that code and can make sure the base function will never 
store the (unretained) pointer somewhere it shouldn't now and in the future. An 
misstep here and you get memory corruption. Seriously, I don't think @system 
code should allow implicit conversions to the base class, it should be explicit.

I am starting to doubt there is any value in inheriting the base 
ref-counted-class from another class.



More information about the Digitalmars-d mailing list