某个程序的堆栈内存有多大,是否有可以设置它的编译器标志?

时间:2021-06-22 02:22:32

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.

正如标题所述:关于堆栈的大小是否有任何一般的“经验法则”。我猜测大小会有所不同,具体取决于操作系统,体系结构,缓存大小,可用RAM数量等。

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?

但是一般可以说什么,或者有没有办法找出,有多少堆栈,这个程序是允许使用的?作为一个额外的问题是有任何方式(使用编译器标志等(在这里主要考虑C / C ++,但也更通用))堆栈的大小可以由用户设置为固定大小?

Btw, I'm asking strictly out of curiosity, I'm not having a stack overflow. :)

顺便说一句,我严格要求出于好奇,我没有堆栈溢出。 :)

2 个解决方案

#1


3  

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).

是的,你可以设置堆栈大小,它通常是一个链接器标志,它取决于你的工具链(通常这是由编译器的名称引用)。

You will also find several existing questions here on *.

您还可以在*上找到几个现有问题。

#2


5  

In Windows the default stack size for a thread is a million bytes, regardless of operating system, etc.

在Windows中,无论操作系统如何,线程的默认堆栈大小都是一百万字节。

In managed code (C#, VB, etc) you can force a new thread to have a different stack size with this ctor:

在托管代码(C#,VB等)中,您可以使用此ctor强制新线程具有不同的堆栈大小:

http://msdn.microsoft.com/en-us/library/5cykbwz4.aspx

To change the stack size of the default thread of a Windows program, whether it is managed or not, you can use the editbin utility:

要更改Windows程序的默认线程的堆栈大小,无论是否管理,您都可以使用editbin实用程序:

http://msdn.microsoft.com/en-us/library/xd3shwhf.aspx

#1


3  

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).

是的,你可以设置堆栈大小,它通常是一个链接器标志,它取决于你的工具链(通常这是由编译器的名称引用)。

You will also find several existing questions here on *.

您还可以在*上找到几个现有问题。

#2


5  

In Windows the default stack size for a thread is a million bytes, regardless of operating system, etc.

在Windows中,无论操作系统如何,线程的默认堆栈大小都是一百万字节。

In managed code (C#, VB, etc) you can force a new thread to have a different stack size with this ctor:

在托管代码(C#,VB等)中,您可以使用此ctor强制新线程具有不同的堆栈大小:

http://msdn.microsoft.com/en-us/library/5cykbwz4.aspx

To change the stack size of the default thread of a Windows program, whether it is managed or not, you can use the editbin utility:

要更改Windows程序的默认线程的堆栈大小,无论是否管理,您都可以使用editbin实用程序:

http://msdn.microsoft.com/en-us/library/xd3shwhf.aspx