Idea: "Explicit" Data Types

Craig Black cblack at ara.com
Fri Apr 11 08:08:41 PDT 2008


>> A problem here arises because even though Foo is allocated on the malloc 
>> heap, it could contain references, pointers, or arrays that touch the GC 
>> heap.  Thus, making Foo "explicit" also denotes that any reference, 
>> pointer or array contained by Foo is also explicit, and therefore does 
>> not refer to data on the GC heap.  Interestingly, this means that 
>> "explicit" would have to be transitive, like D's const.
>>
>
> That seems an idea with limited to no usefullness.
> What if you want to have a class which contains references to both 
> GC-managed data and manually-managed data (which would certainly be a most 
> common case)?

I strongly disagree that this is useless.  I am thinking of porting C++ code 
to D and this would be very useful for that, since my C++ code has 
absolutely no GC at all.  Further, GC objects could contain both explicit 
and non-explicit references.

BTW, I'm not stuck on this particular idea.  Another strategy would be to 
make "explicit" non-transitive.  This would allow for more control, but 
would require the programmer to label more things "explicit".

Either way, the basic concept is what is important.  When you have GC and 
explicit memory managment in the same application, it is beneficial for 
performance to tell the compiler what pointers and references are definitely 
not on the GC heap.  Otherwise the GC is doing unnecessary work.

-Craig 





More information about the Digitalmars-d mailing list