如何更改 .NET 程序的堆栈大小?堆栈、如何更改、大小、程序

2023-09-07 02:50:03 作者:该甪戶不存在

我有一个执行 20 亿次递归调用和堆栈溢出的程序.我进行了更改,然后它仍然需要 40K 递归调用.所以我可能需要几 MB 堆栈内存.我听说堆栈大小默认为 1MB.我尝试在网上搜索.有人说去属性->链接器……在visual studio中,但我找不到.

I have a program that does recursive calls for 2 billion times and the stack overflow. I make changes, and then it still need 40K recursive calls. So I need probably several MB stack memory. I heard the stack size is default to 1MB. I tried search online. Some one said to go properties ->linker .........in visual studio, but I cannot find it.

有人知道怎么增加吗?另外我想知道是否可以在我的 C# 程序中设置它?

Does anybody knows how to increase it? Also I am wondering if I can set it somewhere in my C# program?

附:我使用的是 32 位 winXP 和 64 位 win7.

P.S. I am using 32-bit winXP and 64bit win7.

推荐答案

从 .NET 2.0 和 Win XP 开始设置堆栈大小的最简单方法是使用您想要的堆栈大小生成一个新线程:-

The easiest way to set the stack size from .NET 2.0 and Win XP onwards is to spawn a new thread with the stack size you'd like:-

using System.Threading;

Thread T = new Thread(threadDelegate, stackSizeInBytes);
T.Start();

要更改整个程序的堆栈大小,您必须使用 editbin:-

To change the stack size of the entire program you'd have to use editbin:-

EDITBIN.EXE /STACK:<stacksize> file.exe
 
精彩推荐
图片推荐