简体   繁体   中英

StackOverflowException

With the StackOverflowException are the conditions to be thrown hardcoded or dependent on the machine the code is running on?

I am almost certain the latter but have failed in my searches and don't ask enough questions here.

From the documentation :

... is thrown when the execution stack overflows because it contains too many nested method calls.

Since the size of the stack is architecture-dependent and can even be overridden on a machine, yes, this value is not hard-coded, though it is generally pretty static on Windows. If I remember correctly, it is 1MB in size by default.

Although not a perfect match for your question, see also:

How do you change default stack size for managed executable.net

The exception that is thrown when the execution stack overflows because it contains too many nested method calls. This class cannot be inherited . MSDN

I tried this code with some changes. I alter above statement according to my experience

Framework 4.0 The exception that is thrown when the execution stack overflows because it contains 7573 nested method calls. This class cannot be inherited.

Framework 2.0 The exception that is thrown when the execution stack overflows because it contains 7038 nested method calls. This class cannot be inherited.

Stack frames will vary depending on the addressing mode of your OS. I believe x64 uses slightly larger stack frames. Keep in mind that the process space is capable of growing much more than on x86, so overall you should be able to configure your stack to accept more frames on x64, if RAM and swap file size are not an issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM