Reddit: SafeD - The Safe Subset of D

Kevin Bealer kevinbealer at gmail.com
Mon Mar 31 01:21:03 PDT 2008


Simen Kjaeraas Wrote:

> On Mon, 31 Mar 2008 05:13:50 +0200, Kevin Bealer <kevinbealer at gmail.com>  
> wrote:
> 
> > In languages like D and C++, the garbage collection is conservative, and
> > this means that any pointer-sized block will be considered a pointer if
> > it contains a value that is an address of any area that might still be
> > live.
> >This means that a few "garbage" blocks can be kept around because they
> > are in a memory area which is pointed to by some random integer. This
> > also means that in practice, even for sets of memory blocks that are
> > not circular and might have an obvious destruction order could not be
> > guaranteed to be destroyed in the right order, because a random integer
> > in any of them might make them seem circular, so relying on any policy
> > that tried to detect circularity would be unreliable at best.
> 
> In D, an allocated block can be marked as containing no pointers, and thus
> will not be scanned for things looking pointers. I don't know how good the
> GC/compiler is at understanding these things on its own, but at least a
> programmer can make it more informed.
> 
> --Simen

Yes, and I forgot to mention that at one point the D compiler got an upgrade
that made it more "precise" (the opposite of "conservative" in GC jargon).  It
now knows that a dynamically allocated array of a primitive type (such as an
int[] array or one of the string types) is not a pointer.

So if you are dealing with lots of large matrices or lots of string data, you
should suffer much less from the effects of the accidental retention of blocks.
I don't think it affects for structures, classes, or stack data, though it would
probably be straightforward to do this for structures that had no pointers.

Kevin



More information about the Digitalmars-d-announce mailing list