NonLocalAllocator

NonLocalAllocator is a heap which manages memory with data structures that are independent of the memory itself. This results in a heap design that is different from a local allocator (in-place linked list heap) like GeneralAllocator and many other conventional heaps.

The requirements for (and thus the resulting design of) NonLocalAllocator are primarily based on suggestions received from teams within EA during the requirements-gathering process. NonLocalAllocator isn't implemented simply the same way as GeneralAllocator except being for non-local memory. These differences are driven by the common intended uses for the allocators. For example, GeneralAllocator implements a small-block cache and delayed coalescing of freed blocks, whereas NonLocalAllocator keeps no such cache and always coalesces all free blocks.

Features

NonLocalAllocator has many of the features of PPMalloc GeneralAllocator/GeneralAllocatorDebug, though it implements them within a single class instead of two classes. The features are implemented very similarly and often identically to the equivalent features in GeneralAllocator/GeneralAllocatorDebug.

Future Features

A few features that are currently missing but can be added if there is interest include:

Example Usage

The following demonstrates a minimum usage of NonLocalAllocator.

void* AllocFunction(NonLocalAllocator*, size_t nSize, void*)
{
    return pGeneralAllocator->Malloc(nSize);
}

size_t FreeFunction(NonLocalAllocator*, void* p, size_t nSize, void*)
{
    pGeneralAllocator->Free(p);
}


NonLocalAllocator nla(AllocFunction, FreeFunction, NULL, pNonLocalMemory, nonLocalMemorySize);

void* p = nla.Malloc(1700);
nla.Free(p);