StackOverflowException

偶尔善良 提交于 2021-02-07 14:24:17

问题


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.


回答1:


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.




回答2:


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

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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/1407942/stackoverflowexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!