|
|
#define | CMAlloc CMUTIL_GetMem()->Alloc |
| | Allocate new memory. Use this macro instead of malloc for debugging memory operations.
|
| |
|
#define | CMCalloc CMUTIL_GetMem()->Calloc |
| | Allocate new memory with zero filled. Use this macro instead of calloc.
|
| |
|
#define | CMRealloc CMUTIL_GetMem()->Realloc |
| | Reallocate memory with the given size preserving previous data.
|
| |
|
#define | CMStrdup CMUTIL_GetMem()->Strdup |
| | String duplication.
|
| |
|
#define | CMFree CMUTIL_GetMem()->Free |
| | Deallocate memory which allocated with CMAlloc, CMCalloc, CMRealloc and CMStrdup.
|
| |
|
| void | CMUTIL_Init (CMMemOper memoper) |
| | Initialize this library. This function must be called before calling any function in this library.
|
| |
| CMBool | CMUTIL_Clear (void) |
| | Clear allocated resource for this library.
|
| |
| CMUTIL_Mem * | CMUTIL_GetMem (void) |
| | Global memory operator structure. This object will be initialized with appropriate memory operators in CMUTIL_Init.
|
| |
libcmutils offers three types of memory management:
-
System version malloc, realloc, strdup, and free. This option has no memory management, proper for external memory debugger like 'duma' or 'valgrind'.
-
Memory recycling, all memory allocation will be fit to 2^n sized memory blocks. This option prevents heap memory fragments, supports memory leak detection, and detects memory overflow/underflow corruption while freeing.
-
Memory recycling with stack information. This option is the same as a previous recycling option, except all memory allocation will also create its callstack information, incredibly slow. Only use for memory leak debugging.
◆ CMMemOper
Memory operation types. Refer CMUTIL_Init function for details.
| Enumerator |
|---|
| CMMemSystem | Use system version malloc, realloc, strdup, and free.
|
| CMMemRecycle | Use memory recycle technique.
|
| CMMemDebug | Use memory operation with debugging information.
|
◆ CMUTIL_Init()
Initialize this library. This function must be called before calling any function in this library.
-
CMMemSystem: All memory operations will be replaced with malloc, realloc, strdup, and free. Same as direct call system calls.
-
CMMemRecycle: All memory allocation will be managed with pool. Pool is consists of memory blocks whose size is power of 2 bytes. Recommended for any purpose. This option prevents heap memory fragments and checks memory leak at termination. But a little overhead is required for recycling and needs much more memory usage.
-
CMMemDebug: Option for memory debugging. Any memory operation will be traced, including stack tracing. Recommended only for memory debugging. Much slower than any other options.
- Parameters
-
| memoper | Memory operation initializer. Must be one of CMUTIL_MemRelease, CMUTIL_MemDebug and CMUTIL_MemRecycle. |
◆ CMUTIL_Clear()
Clear allocated resource for this library.
After clearing, all allocated resources are freed, and this library is ready to be initialized again. If any resource is leaked, it will be reported and CMFalse will be returned.
- Returns
- CMTrue if all resources are cleared successfully or inited with CMMemSystem, CMFalse if some resources are leaked, when inited with CMMemRecycle or CMMemDebug.
◆ CMUTIL_GetMem()
Global memory operator structure. This object will be initialized with appropriate memory operators in CMUTIL_Init.
- Returns
- The allocator every object in the library allocates through. It belongs to the library and must not be destroyed.