C++应用程序超出内存但不使用虚拟内存

发布于 2024-09-13 12:47:38 字数 182 浏览 7 评论 0原文

我有一个应用程序,在代码的某些部分使用“new”分配内存并使用“delete”释放内存。 问题是,每当它超过系统的内存限制(比如 2GB)时,Windows 就会向该进程发送 Kill 信号。 我认为这不常见,因为它应该使用交换空间(我认为在 Windows 中它称为虚拟内存),对吧? 我的应用程序是用 C++/Visual Studio 编写的。

I have an application that allocates memory with 'new' and frees them with 'delete' in some parts of the code.
The problem is that whenever it exceeds the memory limit of the system (let's say 2GB), Windows sends a Kill signal to the process.
I think it is not usual since it should use the swap space(I think in windows it is called virtual memory), right?
My application is written in C++/Visual Studio.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

£噩梦荏苒 2024-09-20 12:47:38

Here is how you can make it up to 3GB for a process; That is the absolute max you can have it for 32 bit windows apps. Any more than that and you are going to need to use a 64 bit version of windows.

That is a lot of memory. maybe you could consider splitting your app into multiple processes and communicating between them.

弥枳 2024-09-20 12:47:38

操作系统不会杀死您的应用程序,而是未处理的异常。您将需要使用 perfmon 检查您的应用程序,并观察这些计数器、工作集、虚拟字节、专用字节。当您的保留字节接近 2GB 时,您会遇到异常。所以你提交的字节和 RAM 字节要少得多。

这是一篇关于虚拟地址空间的好文章,包括已提交和保留

这个故事的寓意是,对于 32 位进程,当保留字节接近 2GB 时,不要尝试进行分配。

The OS doesn't kill your app, an unhandled exception does. You will want to examine your app with perfmon, and watch these counters, Working Set, Virtual Bytes, Private Bytes. You will get exceptions when your reserved bytes gets close to 2GB. So your committed bytes and RAM bytes are much less.

Here is a nice article on Virtual Address Space, including committed vs reserved.

The moral of the story, don't try to allocate when the reserved bytes gets close to 2GB, for a 32-bit process.

半窗疏影 2024-09-20 12:47:38

Windows 不使用信号。当内存不足时,您应该得到 std::badalloc 异常。当未被捕获时,将自动运行终止()函数。该异常在“输出”窗口中可见。

Windows doesn't use signals. You should get the std::badalloc exception when you run out of memory. Which, when uncaught, will automatically run the terminate() function. The exception is visible in the Output window.

一桥轻雨一伞开 2024-09-20 12:47:38

我没有仔细研究过这一点,但您可能会在这里找到您想要的答案:

您可以在 c 或 c++ 中分配非常大的单个内存块(> 4GB)吗?

I haven't looked too closely at this, but you may find the answers you want here:

Can you allocate a very large single chunk of memory ( > 4GB ) in c or c++?

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