3.19. SSS Heap ManagementΒΆ

For effective heap management, macros SSS_MALLOC, SSS_CALLOC and SSS_FREE are available in sss/port/ksdk/fsl_sss_types.h for embedded build and in sss/port/default/fsl_sss_types.h for PC/Linux build.

#if defined(USE_RTOS) && USE_RTOS == 1
#include "FreeRTOS.h"

void *pvPortCalloc(size_t num, size_t size); /*Calloc for Heap3/Heap4.*/

#ifndef SSS_MALLOC
#define SSS_MALLOC pvPortMalloc
#endif // SSS_MALLOC

#ifndef SSS_FREE
#define SSS_FREE vPortFree
#endif // SSS_FREE

#ifndef SSS_CALLOC
#define SSS_CALLOC pvPortCalloc
#endif // SSS_CALLOC

#else // !USE_RTOS

#include <stdlib.h>

#ifndef SSS_MALLOC
#define SSS_MALLOC malloc
#endif // SSS_MALLOC

#ifndef SSS_FREE
#define SSS_FREE free
#endif // SSS_FREE

#ifndef SSS_CALLOC
#define SSS_CALLOC calloc
#endif // SSS_CALLOC

#endif // USE_RTOS

These macros are used for heap management operations in middleware and examples. All malloc/calloc/free calls should redirect to the same implementation. The same macro is also used for mbedTLS so that we are consistent across all malloc/free calls. In case of CMake configuration RTOS=FreeRTOS, we define the macros to use FreeRTOS implementation.

Warning

Not using same implementation across the solution could lead to memory corruption.

It is recommended that these macros should be used for all applications. The user can also define their own implementation of heap APIs as platform dependent calls to malloc, calloc and free.