相关疑难解决方法(0)

.NET中的对象引用有多大?

.NET中对象引用的大小是多少?它是否在x86,x64和/或AnyCPU编译之间有所不同?

如果它有所作为,我个人对C#感兴趣.

.net c# reference

68
推荐指数
3
解决办法
2万
查看次数

抛出异常时,使用Lazy <T>的StackOverflowException

一个非常简单的示例应用程序(.NET 4.6.2)在12737的递归深度处产生StackOverflowException ,如果最内部函数调用抛出异常(预期和正常),则递减深度为10243.

如果我使用a Lazy<T>来短暂保存中间结果,则StackOverflowException已经发生在2207的递归深度,如果没有抛出异常并且在递归深度为105,则抛出异常.

注意:如果编译为x64,则深度为105的StackOverflowException 仅可观察.使用x86(32位),效果首先发生在4272的深度.Mono(就像在https://repl.it上使用的那样)可以毫无问题地工作到74200的深度.

StackOverflowException不会在深度递归中发生,而是在升级回主程序时发生.finally块被深度处理,然后程序死掉:

Exception System.InvalidOperationException at 105
Finally at 105
...
Exception System.InvalidOperationException at 55
Finally at 55
Exception System.InvalidOperationException at 54
Finally at 54
Process is terminated due to StackOverflowException.
Run Code Online (Sandbox Code Playgroud)

或者在调试器中:

The program '[xxxxx] Test.vshost.exe' has exited with code -2147023895 (0x800703e9).
Run Code Online (Sandbox Code Playgroud)

谁能解释一下这个?

public class Program
{
    private class Test
    {
        private int maxDepth;

        private int …
Run Code Online (Sandbox Code Playgroud)

c#

9
推荐指数
1
解决办法
512
查看次数

标签 统计

c# ×2

.net ×1

reference ×1