如何确定最大堆栈使用量? [英] How to determine maximum stack usage?
问题描述
有哪些方法可用于确定嵌入式/内存受限系统的最佳堆栈大小?如果它太大,则浪费了可以在其他地方使用的内存.但是,如果它太小,那么我们就会得到这个网站的同名...
What methods are available for determining the optimum stack size for embedded/memory constrained system? If it's too big then memory is wasted that could be used elsewhere. However, if it is too small then we get this website's namesake...
尝试快速启动:Jack Ganssle 在设计嵌入式系统的艺术,通过经验,人们可以学习标准、科学的方法来计算堆栈的适当大小:随机选择一个大小并希望." 谁能做得更好?
To try to jump start things: Jack Ganssle states in The Art of Designing Embedded Systems that, "With experience, one learns the standard, scientific way to compute the proper size for a stack: Pick a size at random and hope." Can anyone do better than that?
要求提供更具体的示例.那么,针对 的 C 程序怎么样?具有 2 kB RAM 的 MSP430 MCU 使用 IAR Embedded Workbench 没有操作系统的工具链?此 IDE 可以在使用 JTAG 调试器时显示堆栈内容和用法.
A more specific example was requested. So, how about a C program targeting an MSP430 MCU with 2 kB of RAM using the IAR Embedded Workbench toolchain without an operating system? This IDE can display the stack contents and usage while using a JTAG debugger.
推荐答案
确定最深堆栈使用的最常见方法是使用一些已知但不寻常的值初始化堆栈内存,然后定期(或在大测试运行)看看该模式在哪里停止.
The most common way to determine the deepest stack usage is to initialize the stack memory with some known but unusual value, then periodically (or at the end of a big test run) see where that pattern stops.
这正是 IAR IDE 确定使用的堆栈数量的方式.
This is exactly how the IAR IDE determines the amount of stack used.
这篇关于如何确定最大堆栈使用量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!