Idea: "Explicit" Data Types

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu Apr 10 11:26:48 PDT 2008


Craig Black wrote:
> Before I get into my proposal, I want to vote for stack maps to be added 
> to D.  IMO, stack maps are the next logical step to making the GC 
> faster.  They don't require a fundamental shift in the library like a 
> moving GC would. Once stack maps are added, then perhaps the following 
> proposal should be considered to glean additional GC performance.
> 
> I'm not stuck on terminology here, so if you don't like the term 
> "explicit" because it's too overloaded, that's fine with me.  Pick 
> another term.  The concept is what's important.  This proposal is about 
> getting GC and explicit memory management to play well together.  The 
> idea is to give the compiler information that allows the GC to scan less 
> data, and hence perform better. Let's start with a class that uses 
> explcit memory management.
> 
> class Foo
> {
> public:
>    new(size_t sz) { return std.c.stdlib.malloc(sz); }
>    delete(void* p) { std.c.stdlib.free(p); }
> }
> 
> This works fine, but doesn't tell the compiler whether data referenced 
> by Foo is allocated on the GC heap or not.  If we preceded the class 
> with some kind of qualifier, like "explicit", this would indicate to the 
> compiler that data referenced by Foo is not allocated on the heap.  
> Note: this constraint can't be enforced by the compiler, but could be 
> enforced via run-time debug assertions.
> 
> explicit class Foo
> {
> public:
>    new(size_t sz) { return std.c.stdlib.malloc(sz); }
>    delete(void* p) { std.c.stdlib.free(p); }
> }
> 
> 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)?


-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list