非递归上下文中的 stackoverflow 异常
我有一个应用程序,它从数据库中获取数据并将其存储在内存中以供以后使用。 我已经针对大约 7000 个数据行测试了该应用程序,但是当我想将其用于 10000 或更多数据行时,我遇到了 StackOverflow 异常。这很奇怪,因为我认为如果我的数据太大,我应该得到 OutOfMemory,而不是 Stackoverflow。
I have an application that fetches data from a database and stores it in memory for later use.
I've tested this application for around 7000 data rows but when I want to use it for 10000 or more I ran into a StackOverflow exception. This is so weird because I think I should get OutOfMemory, not Stackoverflow if my data is too big.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你当然是对的。在 C/C++ 代码中发生堆栈溢出非常容易:
4 确保它在 64 位模式下也发生溢出。但数组是托管代码中的引用类型。它们在堆上分配,而不是在堆栈上。在 C# 代码中,您必须分配一个值类型作为局部变量来占用堆栈空间。唯一有资格让你使用它的值类型是结构体。这很难,您必须声明一个拥有 25 万成员的结构,无论给予还是接受。获得其中一个的唯一可能的方法是从某种工具和巨大的数据库方案自动生成的结构。
那是不会发生的。问题肯定出在您的数据库提供商处。总是用 C 或 C++ 编写。并做一些令人讨厌的事情,例如使用 _alloca() 来破坏堆栈。 C# 中的“stackalloc”关键字。我将避免提及带有 /stack 参数的 editbin.exe 实用程序来增加主线程堆栈的大小,您不必为此烦恼。
与您的数据库提供商联系。
You are right of course. Getting a stack overflow in C/C++ code is pretty easy to do:
The 4 to make sure it blows in 64-bit mode as well. But arrays are reference types in managed code. They get allocated on the heap, not the stack. In C# code, you would have to allocate a value type as a local variable to gobble up stack space. And the only value type type that qualifies to get you anywhere with that is a struct. That's hard, you'd have to declare a struct that has a quarter of a million members, give or take. The only possible way to get one of those is a struct that was auto-generated from some kind of tool and a huge dbase scheme.
That just doesn't happen. Surely the problem is located in your dbase provider. Invariably written in C or C++. And doing something nasty like using _alloca() to blow the stack. The "stackalloc" keyword in C#. I'll avoid mentioning the editbin.exe utility with the /stack argument to increase the size of the main thread stack, you shouldn't have to monkey with that.
Talk to your dbase provider provider.