D Programming Language 2.0

Last update Tue Sep 6 18:55:27 2011


This module contains a struct that wraps D's builtin garbage collected allocator in an allocator interface.

struct GCAllocator;
This struct provides an interface to D's garbage collector using the standard allocator interface.

bool scanForPointers;
This variable controls whether memory allocated via allocate may contain pointers and should be scanned by the garbage collector. This does not affect memory allocated by newArray, array or uninitializedArray since these functions have type information available. The default is true.

void* allocate(size_t nBytes);
Forwards to core.memory.GC.malloc and sets the GC.BlkAttr.NO_SCAN bit if scanForPointers is false.

void free(void* ptr);
Forwards to core.memory.GC.free.

static bool resize(void* ptr, size_t newSize);
Forwards to core.memory.GC.extend.

bool freeIsChecked;
False because the GC doesn't do any checking to ensure that free'd pointers are valid.

static size_t alignBytes(size_t s);
The GC aligns allocations of <16 bytes to 16 bytes, allocations between 16 bytes and the page size to the next larger power of two, and allocations greater than a page size to page boundaries.

static size_t allocSize(size_t s);
The GC rounds allocations of less than 16 bytes to 16 bytes, allocations of between 16 bytes and a page to the next power of two, and allocations greater than a page to the nearest page.

bool isAutomatic;
True because this is just a wrapper around the GC and gets automatically reclaimed.

bool isScoped;
False because GC allocated memory is not freed deterministically when this allocator goes out of scope.

T newArray(T, I...)(I sizes);
Forwards to the new operator for arrays.

    auto alloc = GCAllocator.init;

    // The following are equivalent:
    auto arr = new int[][](42, 86);
    auto arr = alloc.newArray!(int[][])(42, 86);

T uninitializedArray(T, I...)(I sizes);
Same as newArray except skips initialization of elements.

static auto array(R)(R range);
Forwards to .