std.allocator: false pointers

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Fri May 2 10:33:06 PDT 2014


On Fri, 02 May 2014 13:26:41 -0400, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> Why not keep the 3 states, but just treat unmarked blocks as free? Then  
> the next time you go through tracing, change the bit to free if it was  
> already marked.

Sorry, if it was already *unmarked* (or marked as garbage).

essentially:

enum GCState {free, allocated, garbage}

GCState memoryBlocks[];

fullCollect()
{
    foreach(ref st; memoryBlocks)
    {
       final switch(st)
       {
       case GCState.free:
          break;
       case GCState.allocated:
          st = GCState.garbage;
          break;
       case GCState.garbage:
          st = GCState.free;
          break;
       }
    }
    ... // run mark/sweep setting garbage to allocated for reachable blocks
}


More information about the Digitalmars-d mailing list