Heap clarification

delphes wrote on Saturday, February 03, 2018:

Dear all,

When creating a task we pass as parameters heap size for the task, my question is : if this task is allocating dynamic data with pvPortMalloc (lets say heap4 implementation) does the allocated pointer data are limited with the task heap size or by global heap size (defined in freertosconfig.h) ? in fact the heap stack size passed during task create is not so clear for me.


richard_damon wrote on Saturday, February 03, 2018:

The parameter you pass when you create a task is the STACK size (in words) for the task, which if dynamically allocated comes from the heap. It has nothing to do with how much heap space that task can use for other purposes (except that the total available heap space has been reduced by that allocation).

delphes wrote on Sunday, February 04, 2018:

Thanks RIchard for clarification, but I guess the PvPortMalloc is concerning by ConfigtotalHeapsize parameters ?

richard_damon wrote on Sunday, February 04, 2018:

configTOTAL_HEAP_SIZE (in FreeRTOSConfig.h) determines how much heap space to create TOTAL, for all usages (and tasks), unless you are using heap3 (which uses the implementations built in malloc/free and the heap size is set in the way specified by the implementation), or heap5 (where you need to call vPortDefineHeapRegions and pass it the blocks of memory to be used for the heap.

Calls to pvPortMalloc will take from that heap for all usages, and all tasks share this same heap.