How to use SystemView Heap Monitoring - Custom Heap
Revision as of 15:30, 18 July 2023 by Miodrag.stankovic (talk | contribs)
This article assumes a working SystemView setup. To gain some more info on this subject, please consult either the main article (How to use SystemView Heap_Monitoring) or the SystemView documentation.
static void* _MyMalloc(size_t size) {
void* p = malloc(size);
// SystemView needs the real internal heap block size, not the amount requested by the user,
// hence the call to a helper function _GetAllocBlockSize for the currently selected heap type ('Basic')
SEGGER_SYSVIEW_HeapAlloc(__heap_start__, p, _GetAllocBlockSize(size));
return p;
}
/*********************************************************************
- _MyRealloc
- Function description
- Calls the stdlib realloc function and dispatches the SystemView HeapFree and HeapAlloc event.
- Parameters
- p : Pointer to the memory to be reallocated
- size : Size of the reallocated memory block
- Return value
- Pointer to the allocated memory
- /
static void* _MyRealloc(void* p, size_t size) {
void* rp = realloc(p, size);
SEGGER_SYSVIEW_HeapFree(__heap_start__, p);
// SystemView needs the real internal heap block size, not the amount requested by the user,
// hence the call to a helper function _GetAllocBlockSize for the currently selected heap type ('Basic')
SEGGER_SYSVIEW_HeapAlloc(__heap_start__, rp, _GetAllocBlockSize(size));
return rp;
}
/*********************************************************************
- _MyFree
- Function description
- Calls the stdlib free function and dispatches the SystemView HeapFree event.
- Parameters
- p : Pointer to be released
- Return value
- none
- /
static void _MyFree(void* p) {
free(p);
SEGGER_SYSVIEW_HeapFree(__heap_start__, p);
}