Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::MemoryManager Struct Reference

Base class for memory managers. More...

Inheritance diagram for Burger::MemoryManager:
Collaboration diagram for Burger::MemoryManager:

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.

Detailed Description

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.

Member Typedef Documentation

◆ allocate_proc_t

typedef void *( * Burger::MemoryManager::allocate_proc_t) (MemoryManager *pThis, uintptr_t uSize)

Function prototype for allocating memory.

◆ free_proc_t

typedef void( * Burger::MemoryManager::free_proc_t) (MemoryManager *pThis, const void *pInput)

Function prototype for releasing memory.

◆ reallocate_proc_t

typedef void *( * Burger::MemoryManager::reallocate_proc_t) (MemoryManager *pThis, const void *pInput, uintptr_t uSize)

Function prototype for reallocating memory.

◆ shutdown_callback_t

typedef void( * Burger::MemoryManager::shutdown_callback_t) (MemoryManager *pThis)

Function prototype for destructor.

Member Function Documentation

◆ allocate_memory()

void * Burger::MemoryManager::allocate_memory ( uintptr_t uSize)
inlinenoexcept

Allocate memory.


Call the "virtual" function in m_pAllocate to allocate memory

Parameters
uSizeNumber of bytes to allocate
Returns
Pointer to valid memory or nullptr on error or no memory requested.
See also
free_memory(const void*) or allocate_memory_clear(uintptr_t)

◆ allocate_memory_clear()

void *BURGER_API Burger::MemoryManager::allocate_memory_clear ( uintptr_t uSize)
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.

Parameters
uSizeNumber of bytes to allocate.
Returns
nullptr on error or a valid pointer to allocated memory.
See also
allocate_memory(uintptr_t) or reallocate_memory(const void*, uintptr_t)

◆ free_memory()

void Burger::MemoryManager::free_memory ( const void * pInput)
inlinenoexcept

Release memory.


Call the "virtual" function in m_pFree to allocate memory

Parameters
pInputPointer to memory to release
See also
allocate_memory(uintptr_t) or allocate_memory_clear(uintptr_t)

◆ reallocate_memory()

void * Burger::MemoryManager::reallocate_memory ( const void * pInput,
uintptr_t uSize )
inlinenoexcept

Reallocate memory.


Call the "virtual" function in m_pReallocate to reallocate memory

Parameters
pInputPointer to memory to read from and release
uSizeNumber of bytes to allocate
Returns
Pointer to valid memory or nullptr on error or no memory requested.
See also
allocate_memory(uintptr_t) or free_memory(const void*)

◆ shutdown() [1/2]

void BURGER_API Burger::MemoryManager::shutdown ( MemoryManager * pThis)
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)

Parameters
pThisThe "this" pointer
See also
shutdown(void)

◆ shutdown() [2/2]

void Burger::MemoryManager::shutdown ( void )
inlinenoexcept

Shut down the memory manager.


Call the "virtual" function in m_pShutdown to shut down the memory system

See also
shutdown(MemoryManager*)

Member Data Documentation

◆ m_pAllocate

allocate_proc_t Burger::MemoryManager::m_pAllocate

Pointer to allocation function.

◆ m_pFree

free_proc_t Burger::MemoryManager::m_pFree

Pointer to memory release function.

◆ m_pReallocate

reallocate_proc_t Burger::MemoryManager::m_pReallocate

Pointer to the memory reallocation function.

◆ m_pShutdown

shutdown_callback_t Burger::MemoryManager::m_pShutdown

Pointer to the shutdown function.