94
Example
Dim index as Integer Attribute(Volatile)
Sub foo() Attribute(Used,Inline)
End Sub
4.6 Controlling Task Stack and Heap Sizes
For native mode devices, the compiler currently does not produce an estimate of the minimum size of the
stacks for your applications tasks. Consequently, you must determine a suitable size for each task.
Generally, the procedure for doing so is to pick an arbitrary size for each task, say 200 bytes, compile
your application and then run it. If the chosen task stack sizes were sufficiently large, the application will
run normally. If any of task stacks is too small, the application will exhibit erratic behavior, possibly
restarting. Assuming that the application runs correctly, you can add code to determine the amount of
unused space in each task stack by using the System Library function System.TaskHeadRoom().
Depending on the results of this observation, you may choose to increase or decrease the sizes of the
various task stacks.
When using System.TaskHeadRoom() to determine task stack size, it is important to exercise your
application thoroughly to ensure that all execution paths are taken. Moreover, each tasks stack must
have sufficient space to accommodate the stack requirements of any Interrupt Service Handlers that
might be invoked while the task is running.
The diagram below illustrates how RAM is allocated between defined variables, task stacks and the heap.