Base class for memory managers. More...
Public Types | |
typedef void *(* | allocate_proc_t) (MemoryManager *pThis, uintptr_t uSize) |
Function prototype for allocating memory. | |
typedef void(* | free_proc_t) (MemoryManager *pThis, const void *pInput) |
Function prototype for releasing memory. | |
typedef void *(* | reallocate_proc_t) (MemoryManager *pThis, const void *pInput, uintptr_t uSize) |
Function prototype for reallocating memory. | |
typedef void(* | shutdown_callback_t) (MemoryManager *pThis) |
Function prototype for destructor. |
Public Member Functions | |
void * | allocate_memory (uintptr_t uSize) noexcept |
Allocate memory. | |
void | free_memory (const void *pInput) noexcept |
Release memory. | |
void * | reallocate_memory (const void *pInput, uintptr_t uSize) noexcept |
Reallocate memory. | |
void | shutdown (void) noexcept |
Shut down the memory manager. | |
void * | allocate_memory_clear (uintptr_t uSize) noexcept |
Allocate a block of pre-zeroed memory. |
Static Public Member Functions | |
static void | shutdown (MemoryManager *pThis) noexcept |
Default memory manager destructor. |
Public Attributes | |
allocate_proc_t | m_pAllocate |
Pointer to allocation function. | |
free_proc_t | m_pFree |
Pointer to memory release function. | |
reallocate_proc_t | m_pReallocate |
Pointer to the memory reallocation function. | |
shutdown_callback_t | m_pShutdown |
Pointer to the shutdown function. |
Base class for memory managers.
To avoid the use of virtual pointers and to gain ANSI C compatibility, the "base class" has all the virtual functions defined explicitly, and calls to the base class are passed through the function pointers while calls to the derived classed (When known) are performed by direct calls.
Avoiding the use of C++ virtual pointers avoids a redirection when looking up the function pointer to the derived class.
Since this is defined as a base class, it's not meant to be used directly. Derive from this class and either implement a custom memory handler, or use the predefined MemoryManagerANSI or MemoryManagerHandle classes.
typedef void *( * Burger::MemoryManager::allocate_proc_t) (MemoryManager *pThis, uintptr_t uSize) |
Function prototype for allocating memory.
typedef void( * Burger::MemoryManager::free_proc_t) (MemoryManager *pThis, const void *pInput) |
Function prototype for releasing memory.
typedef void *( * Burger::MemoryManager::reallocate_proc_t) (MemoryManager *pThis, const void *pInput, uintptr_t uSize) |
Function prototype for reallocating memory.
typedef void( * Burger::MemoryManager::shutdown_callback_t) (MemoryManager *pThis) |
Function prototype for destructor.
|
inlinenoexcept |
Allocate memory.
Call the "virtual" function in m_pAllocate to allocate memory
uSize | Number of bytes to allocate |
|
noexcept |
Allocate a block of pre-zeroed memory.
Allocate a block of memory and return either nullptr in the case of an out of memory condition or if the amount requested was zero, otherwise return a valid pointer of memory that has been preset to zero.
uSize | Number of bytes to allocate. |
|
inlinenoexcept |
Release memory.
Call the "virtual" function in m_pFree to allocate memory
pInput | Pointer to memory to release |
|
inlinenoexcept |
Reallocate memory.
Call the "virtual" function in m_pReallocate to reallocate memory
pInput | Pointer to memory to read from and release |
uSize | Number of bytes to allocate |
|
staticnoexcept |
Default memory manager destructor.
This function does nothing. It's intended to be a placeholder for derived memory managers that do not have shutdown functions (Such as those that have the OS or ANSI malloc/free to perform these operations)
pThis | The "this" pointer |
|
inlinenoexcept |
Shut down the memory manager.
Call the "virtual" function in m_pShutdown to shut down the memory system
allocate_proc_t Burger::MemoryManager::m_pAllocate |
Pointer to allocation function.
free_proc_t Burger::MemoryManager::m_pFree |
Pointer to memory release function.
reallocate_proc_t Burger::MemoryManager::m_pReallocate |
Pointer to the memory reallocation function.
shutdown_callback_t Burger::MemoryManager::m_pShutdown |
Pointer to the shutdown function.