FreeRTOS heap schemes (heap_1–heap_5)
Five interchangeable memory allocators in FreeRTOS, where you choose how much dynamism you dare by linking in exactly one source file.
FreeRTOS never calls malloc() directly; it calls pvPortMalloc(), and whichever of heap_1.c through heap_5.c you build decides what sits behind it. heap_1 allocates and never frees — which sounds poor but is exactly right for a system that creates all its tasks at startup, and it cannot fragment. heap_2 frees but never merges free blocks, and is now considered legacy. heap_3 wraps the toolchain's own malloc with the scheduler suspended.
heap_4 is the usual choice: first fit with coalescing of adjacent free blocks, in a static array of configTOTAL_HEAP_SIZE bytes. heap_5 does the same across several non-contiguous regions, say internal SRAM plus CCM RAM. Since version 9 (2016) you can also skip the heap entirely and allocate every kernel object statically.