CRM64Pro GDK v0.11.0
A free cross-platform game development kit built on top of SDL 3.0
|
v2.00 (26 June 2023)
Memory Manager module providing a very high performance and thread-safe memory allocation functions.
CRM64Pro Memory Manager(CMem) provides a high performance and thread-safe functions for allocating memory blocks. It also helps to reduce memory fragmentation.
All CRM64Pro GDK modules and external libs (SDL2, libpng, etc.) are using CMem for allocation/deallocation memory.
The client application can use CMem too and could define different module number for having precise and specific statistics.
CMem is composed of three different functional layers:
For setting the memory stats gathering level, you should call to setLogLevel() before calling any other function on your main function in order to capture all information, but you could modify the gathering level at any point just keep in mind that once you call info(), it will dump the information based on current active mode.
Calling destroy() is optional as modern operating system will free all allocated memory but in any case, advised. Call it at the very end of your application, right before the last return instruction. Another option is to use atexit(CMem::destroy) function.
CRM64Pro::string sSource = "mySourceValue";
std::string sDest = sSource; --> Will fail
std::string sDest = sSource.c_str(); --> OK
Enumerations | |
enum | CRM64Pro::CMem::eMemStatsLevel { CRM64Pro::CMem::MSL_NULL = 0 , CRM64Pro::CMem::MSL_NORMAL = 2 , CRM64Pro::CMem::MSL_HIGH = 4 , CRM64Pro::CMem::MSL_VERBOSE = 8 } |
Memory stats gathering level. More... | |
Functions | |
void | CRM64Pro::CMem::setVerboseSampleInterval (Sint32 iInterval) |
Set time interval between each sample when the stats level is MSL_VERBOSE. By default it is set to 500ms. | |
void | CRM64Pro::CMem::setLogLevel (eMemStatsLevel eMSL) |
Set the memory stats gathering level. | |
void | CRM64Pro::CMem::setMsgOutput (Sint32 iLM, const char *szFile) |
Set the memory log mode. | |
Sint32 | CRM64Pro::CMem::setModuleName (Uint32 iModule, const char *szName) |
Set the memory log mode. | |
void * | CRM64Pro::CMem::alloc (size_t iSize, Uint32 iModule) |
Reserve a memory block using C64 Memory Manager. | |
void * | CRM64Pro::CMem::calloc (size_t iNum, size_t iSize, Uint32 iModule) |
Reserve a memory block using C64 Memory Manager and reset it to 0. | |
void * | CRM64Pro::CMem::realloc (void *pMem, size_t iSize, Uint32 iModule) |
Reallocate a memory block using C64 Memory Manager. | |
void * | CRM64Pro::CMem::alloc_aligned (size_t iSize, size_t iAlign, Uint32 iModule) |
Reserve a memory block using C64 Memory Manager aligned to the desired value. | |
void | CRM64Pro::CMem::free (void *pMem) |
Deallocate a memory block using C64 Memory Manager. | |
void | CRM64Pro::CMem::free_aligned (void *pMem) |
Deallocate a memory block using C64 Memory Manager. | |
void | CRM64Pro::CMem::destroy () |
Destroy all internal memory used by the Low-Level Allocator. | |
Sint32 | CRM64Pro::CMem::info (Sint32 iMode) |
Output useful information about the memory usage. | |
Memory stats gathering level.
Enumerator | |
---|---|
MSL_NULL | Disable memory stats gathering. Default value in release code. |
MSL_NORMAL | Normal memory stats gathering. CRM64Pro modules and user allocations are shown individually. Default value in debug mode. |
MSL_HIGH | High memory stats gathering. MSL_NORMAL level plus deallocations are shown for each module. |
MSL_VERBOSE | Verbose memory stats gathering. MSL_HIGH level plus: evolution of allocated memory per module (CMem-Evolution.csv output file) and memory request size histogram per module (CMem-Histogram.csv). |
HandleDLL void CRM64Pro::CMem::setVerboseSampleInterval | ( | Sint32 | iInterval | ) |
Set time interval between each sample when the stats level is MSL_VERBOSE. By default it is set to 500ms.
iInterval | integer with time in milliseconds [1, 30000]. |
HandleDLL void CRM64Pro::CMem::setLogLevel | ( | eMemStatsLevel | eMSL | ) |
Set the memory stats gathering level.
eMSL | stats gathering level. For further information, please check eMemStatsLevel enum. |
HandleDLL void CRM64Pro::CMem::setMsgOutput | ( | Sint32 | iLM, |
const char * | szFile | ||
) |
Set the memory log mode.
iLM | log mode for memory stats. Check LM_NULL, LM_STDOUT, LM_FILE, LM_FILEAPPEND and LM_CONSOLE for further information. |
szFile | name of log file (only makes sense with LM_FILE or LM_FILEAPPEND). Directory separators '\' and '/' are supported. |
HandleDLL Sint32 CRM64Pro::CMem::setModuleName | ( | Uint32 | iModule, |
const char * | szName | ||
) |
Set the memory log mode.
iModule | used for storing who requested the memory for statistics results. Only for custom user modules. |
szName | name of the custom user module. By default, all custom user modules are shown as "User". |
HandleDLL void * CRM64Pro::CMem::alloc | ( | size_t | iSize, |
Uint32 | iModule | ||
) |
Reserve a memory block using C64 Memory Manager.
It is automatically aligned to 4 in 32bits mode and 16 for 64 bits mode.
iSize | size of the memory block, in bytes. |
iModule | used for storing who requested the memory for statistics results. |
HandleDLL void * CRM64Pro::CMem::calloc | ( | size_t | iNum, |
size_t | iSize, | ||
Uint32 | iModule | ||
) |
Reserve a memory block using C64 Memory Manager and reset it to 0.
It is automatically aligned to 4 in 32bits mode and 16 for 64 bits mode.
iNum | number of elements to allocate. |
iSize | size of each element. |
iModule | used for storing who requested the memory for statistics results. |
HandleDLL void * CRM64Pro::CMem::realloc | ( | void * | pMem, |
size_t | iSize, | ||
Uint32 | iModule | ||
) |
Reallocate a memory block using C64 Memory Manager.
It is automatically aligned to 4 in 32bits mode and 16 for 64 bits mode.
pMem | pointer to the memory area to be reallocated. |
iSize | size of the memory block, in bytes. |
iModule | used for storing who requested the memory for statistics results. |
HandleDLL void * CRM64Pro::CMem::alloc_aligned | ( | size_t | iSize, |
size_t | iAlign, | ||
Uint32 | iModule | ||
) |
Reserve a memory block using C64 Memory Manager aligned to the desired value.
iSize | size of the memory block, in bytes. |
iAlign | specifies the alignment. Must be a valid alignment supported by the implementation. Usually a 2^n number is supported. |
iModule | used for storing who requested the memory for statistics results. |
HandleDLL void CRM64Pro::CMem::free | ( | void * | pMem | ) |
HandleDLL void CRM64Pro::CMem::free_aligned | ( | void * | pMem | ) |
Deallocate a memory block using C64 Memory Manager.
pMem | pointer to a memory block previously allocated with alloc_aligned(). |
HandleDLL void CRM64Pro::CMem::destroy | ( | ) |
Destroy all internal memory used by the Low-Level Allocator.
Only applicable when using a Low-Level Allocator. It also call info() for displaying memory stats.
HandleDLL Sint32 CRM64Pro::CMem::info | ( | Sint32 | iMode | ) |
Output useful information about the memory usage.
iMode | 1 for displaying extra information about the Low-Level Allocator (default value) or 0 for disabling it. |