c++程序在“空闲”时崩溃内存为零,但备用内存仍然可用
我有一个问题:
我需要将大约 260mb 的数据加载到一个结构中(使用 fread)。 Windows 资源管理告诉我,我有:
- 2346mb 内存正在使用
- 1478mb 内存处于待机状态
- 248mb 可用内存
但是,当我运行程序并加载数据时,程序崩溃,因为没有剩余“可用”内存。待机内存还剩 1200MB 左右。
我想,当空闲内存为空时,它会自动将备用内存交换到磁盘并释放更多内存吗?
有什么办法可以避免这个问题还是我做错了什么?
I have a bit of a problem:
I need to load around 260mb of data into a struct (with fread). Windows Resource-Management tells me that I have:
- 2346mb memory in use
- 1478mb memory in standby
- 248mb memory free
However, when I run my program and load the data the program crashes at the point where no more "free" memory is left. There are still around 1200mb of standby memory left.
I thought, when the free mem is empty it will automatically swap the standby-memory to the disk and free more memory?
Is there any way to avoid this problem or am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
内存可用并不意味着它是连续的。当您请求这样的大块时,您不太可能得到它,因为可用内存是碎片化的。
Just because the memory is available doesn't mean it's contiguous. When you ask for a big chunk like that, you're unlikely to get it because the available memory is fragmented.
您正在耗尽虚拟地址空间,而不是物理内存。正如您所猜测的,通过缩小磁盘缓存然后使用交换文件可以增加物理内存。然而,虚拟地址空间是一个硬性限制。
You're exhausting your virtual address space, not physical memory. As you guessed, physical memory would be augmented be shrinking the disk cache and then by using the swapfile. Virtual address space is a hard limit, however.