My Language Feature Requests

Christopher Wright dhasenan at gmail.com
Sun Dec 23 06:29:46 PST 2007


This is to fix the stuff I botched with my other reply.

Craig Black wrote:
> a) Disallow overloading new and delete for classes, and make classes 
> strictly for GC, perhaps with an exception for classes instantiated on 
> the stack using scope.

You are just making sure that the garbage collector is handling all 
memory that is associated with objects. I don't see a point to this. The 
collector won't try to move memory that it doesn't control.

You could do bad things with overloading new/delete, but those are 
hardly unique situations.

 > Then the compiler could disallow taking the address of a class field,
 > since we know the resulting pointer would pointer to the GC heap.
 > Note that this would be a compile-time check, and so would not degrade
 > run-time performance.

That's not necessary, since you can map a source range to a destination 
range. It would be a simplifying assumption that improves performance, 
by changing two comparisons and an addition for each pointer (plus one 
subtraction per move) to one comparison and one assignment for each 
pointer. But you're going through a large amount of memory, so that's 
not a serious concern, I think.

> a) Preceding a pointer declaration with fixed would allow that pointer 
> to take the address in the GC heap.

It'd be undefined behavior to do otherwise. But safe as long as no 
collections happen before you use the pointer.

> 
> The fixed pointer will have to know whether or not it points to GC 
> memory so that it doesn't pin non-GC objects.  Using the first idea, we 
> can determine at compile time whether a pointer points to the heap or not.
> 
> Yes, this would be a big change, but not as big as const IMO.  I feel if 
> any feature warrants breaking some code, it would be high-performance 
> GC.  But maybe someone else can find a solution that doesn't break 
> compatibility.
> 
> Thoughts?
> 
> -Craig
> 
> 



More information about the Digitalmars-d mailing list