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
Static vs. dynamic memory allocation, why aren't the examples using xTaskCreateStatic()?
-
- Posts: 9723
- Joined: Thu Nov 26, 2015 4:08 am
Re: Static vs. dynamic memory allocation, why aren't the examples using xTaskCreateStatic()?
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.)
(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.)
Re: Static vs. dynamic memory allocation, why aren't the examples using xTaskCreateStatic()?
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.
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: No registered users and 344 guests