Static vs. dynamic memory allocation, why aren't the examples using xTaskCreateStatic()?

cmorgan
Posts: 89
Joined: Thu Aug 24, 2017 12:52 am

Static vs. dynamic memory allocation, why aren't the examples using xTaskCreateStatic()?

Postby cmorgan » Thu Aug 24, 2017 12:58 am

Hello.

I've noticed that the examples use xTaskCreate() but there aren't any calls to xTaskCreateStatic(). Wouldn't it reduce memory fragmentation and the chance of failing at runtime to use static memory for large buffers like task stacks?

Chris

ESP_Sprite
Posts: 8999
Joined: Thu Nov 26, 2015 4:08 am

Re: Static vs. dynamic memory allocation, why aren't the examples using xTaskCreateStatic()?

Postby ESP_Sprite » Thu Aug 24, 2017 3:12 am

Tasks are usually created on startup, when there's still plenty of memory available. Also, not all memory that is available at runtime is also available at compile time (because the heap allocator can use some bits of memory that are initially used but freed up somewhere early in the boot process).

(Also, creating tasks in static memory was only later added to the FreeRTOS in the ESP32 and is a fairly late addition into FreeRTOS itself as well, hence most 'normal' FreeRTOS examples use the dynamic functions as well. Something can be said for not pulling undue attention to something silly as task creation methods when the examples are meant to illustrate something else.)

cmorgan
Posts: 89
Joined: Thu Aug 24, 2017 12:52 am

Re: Static vs. dynamic memory allocation, why aren't the examples using xTaskCreateStatic()?

Postby cmorgan » Thu Aug 24, 2017 3:41 pm

Ahh ok. While I'll probably use static tasks to ensure memory is available I can appreciate using some dynamic memory if that can use memory reserved for the boot process.

I also agree about not over complicating examples. I searched and didn't see anyone else ask about the topic of static allocation, something relatively typical in embedded systems so maybe this discussion will help others that might have a similar question.

Who is online

Users browsing this forum: Bing [Bot] and 78 guests