非递归上下文中的 stackoverflow 异常

发布于 2024-09-11 16:22:48 字数 170 浏览 6 评论 0原文

我有一个应用程序,它从数据库中获取数据并将其存储在内存中以供以后使用。 我已经针对大约 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南…巷孤猫 2024-09-18 16:22:48

你当然是对的。在 C/C++ 代码中发生堆栈溢出非常容易:

int _tmain(int argc, _TCHAR* argv[])
{
    char buffer[4 * 1024 * 1024];
    return 0;
}

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:

int _tmain(int argc, _TCHAR* argv[])
{
    char buffer[4 * 1024 * 1024];
    return 0;
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文