Where can I find out how much heap is used in creating a task, and what things affect the amount of heap used? I know it’s going to be different for different platforms. I’m using an ARM7 and it seems like the minimum is 404 bytes, often 532 or 660 bytes, and one of my tasks uses 812 bytes off the heap on creation. Do these all look reasonable, and why the differences?
Ram used = sizeof( tskTCB ) + ( usStackSize * sizeof( portSTACK_TYPE ) )
usStackSize is the parameter passed to xTaskCreate().
portSTACK_TYPE is unsigned long on an ARM7.
There may also be a couple of extra bytes to ensure the correct alignment.
>>> Ram used = sizeof( tskTCB ) + ( usStackSize * sizeof( portSTACK_TYPE ) )
Good afternoon, Dave.
How much of that comes from the heap? I assume (usStackSize * sizeof(portSTACK_TYPE)) goes in the stack area, right?
Heap usage for tasks startups for three representative tasks are 404, 532, and 660 bytes. Stack allocations are 64, 96, and 128 respectively. Per the formula above, then, the RAM usage should be 396, 524, and 652 respectively. Each calculated value is 8 bytes below the actual value, so I assume the extra 8 bytes are overhead plus alignment.
It does look like each task is taking heap memory for its stack. Project configuration for the IAR compiler has a STACKS segment (576 bytes) and a HEAP segment (10752 bytes). If the tasks build their stacks on the heap, what is the STACKS segment for?
>How much of that comes from the heap? I assume (usStackSize
>* sizeof(portSTACK_TYPE)) goes in the stack area, right?
The memory is used as the stack for the task but comes from the FreeRTOS heap - heap_1, heap_2, heap_3, or whatever you have used.
The stack segment is used for main() before the kernel starts but can be used for whatever you like after that. You can use it for the IRQ stack to avoid allocating memory for both.
The heap segment setup by the compiler is only used if you are using heap_3 or calling malloc() directory (instead of pvPortMalloc). If you are not doing either of these then set it to its minimum value, probably 4.