libcmutils 0.6.5
Multi-platform C99 utility library
Loading...
Searching...
No Matches
Initialization and memory operations.

Data Structures

struct  CMUTIL_Mem
 

Macros

#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.
 

Enumerations

enum  CMMemOper { CMMemSystem = 0 , CMMemRecycle , CMMemDebug }
 Memory operation types. Refer CMUTIL_Init function for details. More...
 

Functions

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_MemCMUTIL_GetMem (void)
 Global memory operator structure. This object will be initialized with appropriate memory operators in CMUTIL_Init.
 

Detailed Description

libcmutils offers three types of memory management:

Enumeration Type Documentation

◆ CMMemOper

enum 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.

Function Documentation

◆ CMUTIL_Init()

void CMUTIL_Init ( CMMemOper  memoper)

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
memoperMemory operation initializer. Must be one of CMUTIL_MemRelease, CMUTIL_MemDebug and CMUTIL_MemRecycle.

◆ CMUTIL_Clear()

CMBool CMUTIL_Clear ( void  )

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()

CMUTIL_Mem * CMUTIL_GetMem ( void  )

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.