Allocator interface for dynamic memory allocations.
The Umbra classes that require dynamic allocations do so by callbacks to the user provided Allocator implementation. This is to give the user full control of the memory management. When no user implementation is provided, a default implementation that uses std::malloc and std::free is used.
- ~Allocator(void) virtual
Allocator:: allocate(size_t size,
const char* info = NULL) pure virtual
Allocate a block of memory.
|size||The requested allocation size, in bytes.|
|info||A freeform description of the allocation, for optional tracking of where the allocations are being made from.|
|Returns||A pointer to the allocated block of memory.|
The implementation of this class should reserve and return a block contiguous block of memory of size indicated by the size parameter. The semantics are similar to std::malloc. Note that Umbra does internal memory management on top of the allocations through this interface to reduce the number of calls.
Umbra makes no effort of mutually excluding calls to the allocation interface, whether or not the implementations should do this depends on the usage pattern of the Umbra public interfaces: if calls are made to the Umbra modules simultaneously from multiple threads then thread safety needs to be implemented in the provided allocator as well.
Allocator:: deallocate(void* ptr) pure virtual
Free a block of memory.
|ptr||Pointer to memory block previously allocated with allocate().|
Free a previously allocated block of memory and make it available for reuse.