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::GlobalMemoryManager Class Reference

Singleton class for global memory allocation. More...

Collaboration diagram for Burger::GlobalMemoryManager:

Static Public Member Functions

static MemoryManagerinit (MemoryManager *pInstance) noexcept
 Initialize the global memory allocator.
 
static void shutdown (MemoryManager *pPrevious=nullptr) noexcept
 Shut down the global memory allocator.
 
static MemoryManagerget_instance (void) noexcept
 Return the instance of the active global memory manager.
 

Static Private Attributes

static MemoryManagerg_pInstance
 Pointer to the currently active memory manager.
 

Detailed Description

Singleton class for global memory allocation.


To implement a global, redirectable version of malloc(), free(), or realloc() for Burgerlib, a method was needed to contain the instance pointer of a memory manager for the global use of Burger and retain the ability to change the implementation at will. This was needed since Burgerlib Memory Managers are all class based so a this pointer is needed in all calls whereas the ANSI calling convention assumes a global implementation.

By using this class, which is initialized either with MemoryManagerANSI or MemoryManagerHandle all functions that allocate memory from the global pool can and will be redirected.

Note
This class is assumed to have functions that are thread safe. Any custom implementations on target platforms that support multi-threading must all be multi-core thread safe.
Since this a reference to the controlled class, NEVER manually up cast the global instance of this class. Use the get_instance(void) function to get the pointer to the real class if up casting is desired for system specific functionality is desired.

Member Function Documentation

◆ get_instance()

static MemoryManager * Burger::GlobalMemoryManager::get_instance ( void )
inlinestaticnoexcept

Return the instance of the active global memory manager.


Returns
Pointer to the current global memory manager, nullptr if none is active.

◆ init()

Burger::MemoryManager *BURGER_API Burger::GlobalMemoryManager::init ( MemoryManager * pInstance)
staticnoexcept

Initialize the global memory allocator.


This function copies the pointer to this MemoryManager class to the global instance pointer and will use this instance for all memory operations.

Note
The MemoryManager is not copied, so the class should not go out of scope without a call to either shutdown() or reset to another implementation
Parameters
pInstancePointer to an initialized MemoryManager.
Returns
Pointer to the previous version of the MemoryManager
See also
shutdown(MemoryManager *)

◆ shutdown()

void BURGER_API Burger::GlobalMemoryManager::shutdown ( MemoryManager * pPrevious = nullptr)
staticnoexcept

Shut down the global memory allocator.


Shut down the memory allocator through the MemoryManager::m_pShutdown pointer.

Note
This call will zero out all entries in this class, so all future use of this class except for a call to init(MemoryManager*) will result in an assert or page fault.
Parameters
pPreviousPointer to an previous MemoryManager.
See also
init(MemoryManager*)

Member Data Documentation

◆ g_pInstance

Burger::MemoryManager * Burger::GlobalMemoryManager::g_pInstance
staticprivate

Pointer to the currently active memory manager.