XLE
v0.02.0
|
A simple but efficient mini heap implement More...
#include <MiniHeap.h>
Classes | |
class | Allocation |
Public Member Functions | |
Allocation | Allocate (unsigned size) |
void | Free (void *ptr) |
void | AddRef (Allocation marker) |
void | Release (Allocation marker) |
Protected Attributes | |
std::unique_ptr< Pimpl > | _pimpl |
A simple but efficient mini heap implement
This class is used to manage arbitrary allocations.
It avoids fragmentation for small allocations. It's works best with small short-lived allocations. Originally designed to manage upload data for constant buffers. Often it's best to dedicate a separate mini heap for each allocation type (eg, one might be for constant buffers, another might be for temporary strings).
Generally allocation should be fast. However, free can take a little more time. If allocation/free performance is critical it might be better to just use a heap that continually grows, until everything is destroyed at the same time (eg, a thread locked frame temporaries heap)
Reference counting is built into the heap (just for convenience) However, note that AddRef/Release might be a bit slower than usual because we have to search for the right block, first! To use reference counting, you must record and use the "MiniHeap::Allocation" objects. We need this to track the internal heap block. Reference counting is too slow without this; so AddRef/Release methods without the allocation marker are not provided.
Note that when allocations are first returned, they start with a reference count of 1. That is, the follow code will create and then destroy a single block: