ChunkAllocator

Allocate a chunk of elements at once, then use the chunk to return elements. This makes allocating individual elements more efficient because the GC isn't used for allocating every element, only every chunk of elements. * The only requirement is that the size of V is >= size of a pointer. This is because the data V contains is used as a pointer when freeing the element. * If an entire chunk of elements is freed, that chunk is then returned to the GC.

Members

Functions

allocate
V* allocate()

Allocate a V*

free
void free(V* v)

free a V*

freeAll
void freeAll()

Deallocate all chunks used by this allocator.

Structs

chunk
struct chunk

A chunk of elements

element
struct element

This is the form used to link recyclable elements together.

Variables

freeNeeded
enum bool freeNeeded;

Free is needed to recycle nodes for another allocation.

fresh
chunk* fresh;

The fresh chunk. This is only used if no elements are available in the used chain.

nextFresh
uint nextFresh;

The next element in the fresh chunk. Because we don't worry about the free list in the fresh chunk, we need to keep track of the next fresh element to use.

used
chunk* used;

The chain of used chunks. Used chunks have had all their elements allocated at least once.

Meta