FreeRTOS heap allocation at compile time.

TibiToz
Posts: 7
Joined: Mon Aug 10, 2020 1:46 pm

FreeRTOS heap allocation at compile time.

Postby TibiToz » Thu Mar 24, 2022 10:38 am

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

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: FreeRTOS heap allocation at compile time.

Postby WiFive » Fri Mar 25, 2022 4:18 am

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.

Who is online

Users browsing this forum: No registered users and 100 guests