0
0
FreeRTOSprogramming~10 mins

Static vs dynamic allocation (configSUPPORT_STATIC_ALLOCATION) in FreeRTOS - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Static vs dynamic allocation (configSUPPORT_STATIC_ALLOCATION)
Start Task Creation
Check configSUPPORT_STATIC_ALLOCATION
Use Static
Allocation
Task Created
Task Runs Normally
When creating a task, FreeRTOS checks if static allocation is enabled. If yes, it uses static memory; if no, it uses dynamic memory. Then the task runs normally.
Execution Sample
FreeRTOS
if(configSUPPORT_STATIC_ALLOCATION) {
  xTaskCreateStatic(...);
} else {
  xTaskCreate(...);
}
This code chooses static or dynamic task creation based on the configSUPPORT_STATIC_ALLOCATION setting.
Execution Table
StepconfigSUPPORT_STATIC_ALLOCATIONActionMemory UsedResult
11 (enabled)Call xTaskCreateStatic()Static memory (user-provided buffers)Task created with static allocation
20 (disabled)Call xTaskCreate()Dynamic memory (heap allocation)Task created with dynamic allocation
3-Task runsMemory used as allocatedTask executes normally
💡 Task creation ends after allocation; task runs normally regardless of allocation method.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
configSUPPORT_STATIC_ALLOCATIONSet by userCheckedCheckedNo change
Task MemoryNoneStatic buffers assigned if enabledHeap memory assigned if disabledAllocated memory remains during task life
Key Moments - 3 Insights
Why does FreeRTOS need to know about static allocation before creating a task?
Because static allocation requires the user to provide memory buffers before task creation, unlike dynamic allocation which uses heap memory internally. See execution_table step 1.
What happens if configSUPPORT_STATIC_ALLOCATION is disabled but xTaskCreateStatic() is called?
The code will not compile or link correctly because static allocation support is disabled. The execution_table shows that static allocation only happens if configSUPPORT_STATIC_ALLOCATION is enabled.
Does the task behave differently after creation depending on allocation method?
No, once created, the task runs the same way regardless of static or dynamic allocation. See execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what memory is used when configSUPPORT_STATIC_ALLOCATION is 1?
AStatic memory buffers provided by user
BHeap memory allocated dynamically
CNo memory allocated
DMemory allocated on stack
💡 Hint
Refer to execution_table row 1 under 'Memory Used'
At which step does the task start running normally regardless of allocation?
AStep 1
BStep 2
CStep 3
DBefore Step 1
💡 Hint
Check execution_table row 3 'Result' column
If configSUPPORT_STATIC_ALLOCATION is set to 0, which function is called to create the task?
AxTaskCreateStatic()
BxTaskCreate()
CvTaskStartScheduler()
DxTaskCreateDynamic()
💡 Hint
See execution_table row 2 'Action' column
Concept Snapshot
FreeRTOS task creation uses static or dynamic allocation.
Set configSUPPORT_STATIC_ALLOCATION to 1 to enable static allocation.
Static allocation requires user buffers; dynamic uses heap.
Use xTaskCreateStatic() if static enabled, else xTaskCreate().
Task runs the same regardless of allocation method.
Full Transcript
When FreeRTOS creates a task, it first checks the configSUPPORT_STATIC_ALLOCATION setting. If this is enabled (set to 1), the system uses static allocation, meaning the user must provide memory buffers for the task's stack and control block. This is done by calling xTaskCreateStatic(). If static allocation is disabled (set to 0), FreeRTOS uses dynamic allocation, which means it allocates memory from the heap internally by calling xTaskCreate(). After allocation, the task runs normally in both cases. This choice affects how memory is managed but not how the task behaves once running. Beginners often wonder why this setting matters; it is because static allocation avoids heap usage and can improve reliability in some systems. The execution table shows the steps clearly: checking the setting, choosing the allocation method, and running the task. The variable tracker shows that configSUPPORT_STATIC_ALLOCATION does not change during execution, but the task memory changes depending on the method chosen.