TempAlloc and druntime GC

Daniel Keep daniel.keep.lists at gmail.com
Mon Jan 19 15:55:06 PST 2009



dsimcha wrote:
> [snip]
> The problem with this is that I'd ideally like to control whether each
> TempAlloc-allocated object is scanned by the GC individually, rather than scanning
> the entire used portion of the TempAlloc stack.  Having to create and store a
> context struct for every object would be incredibly inefficient.  Scanning the
> entire used portion would be incredibly conservative.
> 
> At an implementation level, TempAlloc already uses an array of void*s internally
> to track what it's allocated (only one per object, in an array, not a linked list)
> so that it can be freed properly.  Since TempAlloc allocates using 16-byte
> alignment, I was planning to avoid any extra overhead by storing the scan/noscan
> bits in the low order bits of these pointers.
> [snip]

Just a random thought here; what if you had this:

struct Context
{
    void*    begin;
    void*    end;
    Context* next;
}

struct FatContext
{
    void*    begin;
    void*    end;
    Context* next;
    uint*    bitmap;
}

void attachFatContext( FatContext* ctx )
{
    assert( ctx.next & 3 == 0 );
    ctx.next |= 1;
    attachContext( cast(Context*) ctx );
}

FatContext* isFatContext( Context* ctx )
{
    return (ctx.next & 1) ? cast(FatContext*) ctx : null;
}

Context* nextContext( Context* ctx )
{
    return ctx.next & ~3;
}

Now, we assume that bitmap is a pointer to the first element of an array
of uints that's (end-begin)/16 long.  You'd only need one bit per 16
bytes, and it'd let you change the scan/noscan of any area of memory
without having to talk to the GC every time.

  -- Daniel



More information about the Digitalmars-d mailing list