Measuring stack and heap usage

Stack memory is used as scratch space for each thread of execution. Heap memory is used only in rare cases because most memory usage is determined at link time. Heap is used for certain matrix operations (for example, the inverse function) and is tracked so you can be updated continuously on heap usage.  To examine the stack and heap:

1.    In the Tools > Code Gen dialog box, activate Add Stack Check Code and click Compile.

2.    If you view the generated code, the GET_MAX_STACK_USED(); function appears in the code.

3.    Download and run the application on the target.

Allow the target to execute with ample runtime to exercise all significant functions.

4.    Under Embedded > your-device > Target Interface, choose Get Target Stack and Heap to display the maximum stack and heap usage encountered during target execution.