Page 1 of 1

FreeRTOS heap allocation at compile time.

Posted: Thu Mar 24, 2022 10:38 am
by TibiToz
I'm monitoring my heap usage with esp_get_free_heap_size() during the program's lifetime. I have noticed a strange behavior (at least for my level of comprehension of the FreeRTOS).

Let's assume these simple lines of code :

Code: Select all

if ( 1 > 2)
{
	xTaskCreate(&myTask);
}
Obviously the condition will never be true and the task will never start. I can monitor my heap size and get value X with this code compiled.

Now, if I simply comment the task creation :

Code: Select all

if ( 1 > 2)
{
	//xTaskCreate(&myTask);
}
and I monitor again my heap size after compilation, this value will be > X.

I cannot understand how is this possible and how FreeRTOS is allocating the heap usage at compile time. Any answers will greatly help me, Thank you.

Tibi

Re: FreeRTOS heap allocation at compile time.

Posted: Fri Mar 25, 2022 4:18 am
by WiFive
To track memory at compile time use idf.py size. The initial heap size can increase if the compiler reserves less memory for example if it optimizes out functions and variables. Otherwise heap is dynamic and you can use heap tracing to analyse it.