WE310F5  39.00.000
M2MB HEAP

This section describes the M2MB API for the heap stat module. More...

Data Structures

struct  M2MB_ALLOC_NODE_DATA
 Structure for node data. More...
 
typedef struct M2MB_ALLOC_NODE_DATA M2MB_HEAP_ALLOC_NODE_DATA_T
 Structure for node data. More...
 
void * m2mb_heap_malloc (UINT32 reqBytes, char *file, int line)
 m2mb_heap_malloc allocates the memory for requested bytes(size) along with 20 bytes for M2MB_HEAP_ALLOC_NODE_T. More...
 
void * m2mb_heap_realloc (void *ptr, UINT32 reqBytes, char *file, int line)
 m2mb_heap_realloc is called to reallocate the memory of size reqBytes pointed by pointer ptr. More...
 
void m2mb_heap_free (void *ptr, char *file, int line)
 m2mb_heap_free is called to frees the memory pointed by ptr. More...
 
VOID m2mb_heap_log_init (VOID)
 m2mb_heap_log_init is called to initialize the heap allocation list. More...
 
M2MB_HEAP_ALLOC_NODE_DATA_Tm2mb_heap_getList (VOID)
 m2mb_heap_getList is called to get the pointer to the current node in the M2MB_HEAP_LOG_LIST_T. More...
 
VOID m2mb_heap_resetTrace (VOID)
 m2mb_heap_resetTrace resets the current node in the list as the trace node. More...
 
UINT32 m2mb_heap_getSize (UINT8 *ptr)
 m2mb_heap_getSize returns the size of current node data in bytes. More...
 
INT32 m2mb_heap_stat (UINT32 *total_bytes, UINT32 *free_bytes)
 m2mb_heap_stat is called to get the status. More...
 

Detailed Description

This section describes the M2MB API for the heap stat module.

Heap stat module provides API to get the current statistics of heap. It gives the total size of heap and available bytes in the heap. User may not be able to allocate memory even the size the user wants to allocate is lesser than the size available. This is because of fragmentation in the heap area.

Typedef Documentation

◆ M2MB_HEAP_ALLOC_NODE_DATA_T

Structure for node data.

Allocation node data, the node carries the information of the memory block allocated.

Function Documentation

◆ m2mb_heap_free()

void m2mb_heap_free ( void *  ptr,
char *  file,
int  line 
)

m2mb_heap_free is called to frees the memory pointed by ptr.

m2mb_heap_free is called to frees the memory pointed by ptr along with deleting the node carrying memory log details.

Parameters
[in]ptrPointer to memory block to be freed.
[in]fileName of the file where m2mb_heap_free is called.
[in]lineLine number where m2mb_heap_free is called.
Note
<Notes> Example
int main()
{
...
...
int ptr = MALLOC(sizeof(int));
...
...
m2mb_heap_free(ptr, __FILE__, __LINE__);
...
...
}

◆ m2mb_heap_getList()

M2MB_HEAP_ALLOC_NODE_DATA_T* m2mb_heap_getList ( VOID  )

m2mb_heap_getList is called to get the pointer to the current node in the M2MB_HEAP_LOG_LIST_T.

m2mb_heap_getList returns pointer to the current node list, M2MB_HEAP_LOG_LIST_T.

Returns
Pointer of type M2MB_HEAP_ALLOC_NODE_DATA_T.
Note
<Notes> Example
int main()
{
...
...
ifdef M2MB_HEAP_DEBUG
...
...
...
...
}

◆ m2mb_heap_getSize()

UINT32 m2mb_heap_getSize ( UINT8 ptr)

m2mb_heap_getSize returns the size of current node data in bytes.

m2mb_heap_getSize returns the size of current node data in bytes.

Parameters
[in]ptrPointer to the memory block.
Note
<Notes> Example
int main()
{
...
...
ifdef M2MB_HEAP_DEBUG
...
...
int ptrToBlock = MALLOC(size(25));
...
...
int get_size = m2mb_heap_getSize(ptrToBlock);
...
...
}

◆ m2mb_heap_log_init()

VOID m2mb_heap_log_init ( VOID  )

m2mb_heap_log_init is called to initialize the heap allocation list.

m2mb_heap_log_init initializes the list M2MB_HEAP_LOG_LIST_T used to log every memory allocation.

Note
m2mb_heap_log_init should be called in the beginning of app_start() in any application before any API if M2MB_HEAP_DEBUG is enabled.

Example

int main()
{
...
...
ifdef M2MB_HEAP_DEBUG
...
...
}

◆ m2mb_heap_malloc()

void* m2mb_heap_malloc ( UINT32  reqBytes,
char *  file,
int  line 
)

m2mb_heap_malloc allocates the memory for requested bytes(size) along with 20 bytes for M2MB_HEAP_ALLOC_NODE_T.

m2mb_heap_malloc allocates the memory of 'size+20' bytes.

Parameters
[in]reqBytesSize of the memory block.
[in]fileName of the file where m2mb_heap_free is called.
[in]lineLine number where m2mb_heap_free is called.
Note
<Notes> Example
int main()
{
...
...
int realloc_ptr = m2mb_heap_malloc(20, __FILE__, __LINE__);
...
...
}

◆ m2mb_heap_realloc()

void* m2mb_heap_realloc ( void *  ptr,
UINT32  reqBytes,
char *  file,
int  line 
)

m2mb_heap_realloc is called to reallocate the memory of size reqBytes pointed by pointer ptr.

m2mb_heap_realloc is called to reallocate the memory of size reqBytes pointed by pointer ptr.

Parameters
[in]ptrPointer to memory block to be reallocated.
[in]reqBytesSize of the memory block to be reallocated.
[in]fileName of the file where m2mb_heap_free is called.
[in]lineLine number where m2mb_heap_free is called.
Note
<Notes> Example
int main()
{
...
...
int ptr = MALLOC(sizeof(int));
...
...
int realloc_ptr = m2mb_heap_realloc(ptr, sizeof(20), __FILE__, __LINE__);
...
...
}

◆ m2mb_heap_resetTrace()

VOID m2mb_heap_resetTrace ( VOID  )

m2mb_heap_resetTrace resets the current node in the list as the trace node.

m2mb_heap_resetTrace resets the current node in the list as the trace node.

Note
<Notes> Example
int main()
{
...
...
ifdef M2MB_HEAP_DEBUG
...
...
...
...
}

◆ m2mb_heap_stat()

INT32 m2mb_heap_stat ( UINT32 total_bytes,
UINT32 free_bytes 
)

m2mb_heap_stat is called to get the status.

m2mb_heap_stat gets the memory heap status: Total bytes and Free bytes.

Parameters
[out]total_bytesPointer to a UINT32 to hold the total amount of heap bytes
[out]free_bytesPointer to a UINT32 to hold the approximated amount of free heap bytes
Returns
Returns 0 on success, or a different code on error
Note
<Notes> Example
int main()
{
UINT32 *total_bytes;
UINT32 *free_bytes;
if(!m2mb_heap_stat(&total_bytes, free_bytes))
//SUCCESS
else
//FAIL
}