Manual memory management in D2

bearophile bearophileHUGS at lycos.com
Tue Jul 13 12:42:05 PDT 2010


Andrei Alexandrescu:
> But manual deletion has no business in the garbage collected 
> heap. That currently druntime provides it is an accident caused by the 
> current implementation; most GC's cannot provide efficient manual 
> reclamation. And they shouldn't anyway.

The structure of memory blocks is like a graph, generally each memory zone can have inbound references and outbound ones.
In unsafe D if I am "sure" a GC-managed memory zone (like a large array of doubles or a large associative array from int to double) has no inbound references, then I want a way to deallocate it quickly.
In SafeD that can't be allowed, because if I am wrong that operation can generate some broken references.
So in SafeD the delete operation can be replaced by something safer, a way to tell the GC to deallocate just a specific object, walking the graph and setting to null all the inbound pointers (this is a slower operation).
A problem is that the GC is conservative, so some of those references can be something different, and setting them to null can damage the program state. So it seems even less safe.

Bye,
bearophile


More information about the Digitalmars-d mailing list