问题描述
正如标题所述:关于堆栈大小是否有任何一般的经验法则".我猜大小会因操作系统、架构、缓存大小、可用 RAM 大小等而有所不同.
As the title states: Is there any general "rule of thumb" about the size of the stack. I'm guessing the size will vary depending on the OS, the architecture, the size of the cache(s), how much RAM is available etc.
但是一般来说可以说什么,或者有什么方法可以找出,这个程序允许使用多少堆栈?.作为一个额外的问题,是否有任何方法(使用编译器标志等(这里主要考虑 C/C++,但也更通用))堆栈的大小可以由用户设置为固定大小?
However can anything be said in general, or is there any way to find out, how much of the stack, this program is allowed to use?. As a bonus question is there any way (with compiler flags etc. (thinking mostly C/C++ here, but also more general)) that the size of the stack can be set to a fixed size by the user?
顺便说一句,我完全出于好奇而问,我没有堆栈溢出.:)
Btw, I'm asking strictly out of curiosity, I'm not having a stack overflow. :)
推荐答案
是的,你可以设置堆栈大小,它通常是一个链接器标志,它取决于你的工具链(通常由编译器的名称引用).
Yes you can set the stack size, it usually is a linker flag, and it depends on your toolchain (typically this is referred to by the name of the compiler).
- 对于 Microsoft Visual C++,使用
/F
选项 来改变大小,DUMPBIN/HEADERS
看看什么设置是. - 对于 GCC 工具链和大多数其他 Unix 链接器,使用
-Wl,--stack
- For Microsoft Visual C++, use the
/F
option to change the size, andDUMPBIN /HEADERS
to see what the setting is. - For the GCC toolchain and most other Unix linkers, use
-Wl,--stack
您还可以在 StackOverflow 上找到几个现有问题.
You will also find several existing questions here on StackOverflow.
这篇关于某个程序的堆栈内存有多大,是否有任何编译器标志可以设置它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!