简体   繁体   English

当vector <vector <vector <int> >>大于RAM时,为什么我的程序会产生正确的输出?

[英]Why does my program produce correct output when my vector< vector< vector<int> > > is larger than the RAM?

I have implemented a system which takes as an input some data, and produces as a result a very big vector< vector< vector<int> > > which I then output to a file. 我已经实现了一个系统,它将一些数据作为输入,然后产生一个非常大的vector< vector< vector<int> > > ,然后我将其输出到一个文件中。

After calculating the result I decided to count the total amount of numbers inside this final 3d vector and it was: 1386502951 在计算结果后,我决定计算最终三维向量内的数字总数,它是: 1386502951

that means that the total amount of memory needed to store this vector is at least 1386502951*4 bytes = 5.16512599 GB 这意味着存储此向量所需的内存总量至少为1386502951*4 bytes = 5.16512599 GB

however my RAM memory is only 4 GB. 但是我的RAM内存只有4 GB。

Can someone explain to me how this is possible? 有人可以向我解释这有可能吗?

Thank you in advance! 先感谢您!

Your application is able to allocate more memory than is physically installed on your computer because it supports virtual memory. 您的应用程序能够分配比计算机上物理安装的内存更多的内存,因为它支持虚拟内存。 Allocation, paging and releasing virtual memory is handled by the operating system to allow your application to run without having to worry about exhausting physical memory. 分配,分页和释放虚拟内存由操作系统处理,以允许您的应用程序运行,而不必担心耗尽物理内存。

Keep in mind that releasing the allocated memory may not occur immediately when your application frees memory from it's heap. 请记住,当您的应用程序从其堆中释放内存时,可能不会立即释放释放已分配的内存。 This has a tendency to make people think their application is at times using more memory that it should. 这倾向于让人们认为他们的应用程序有时会使用更多的内存。

There are a good number of websites that discuss the topic of virtual and physical and any API's provided by the operating that allow you to have some control over it. 有很多网站讨论虚拟和物理主题以及操作提供的任何API,允许您对其进行控制。 A quick Google Dance should provide you with a significant number of links on the subject. 快速的Google Dance应该会为您提供大量有关此主题的链接。

There could be a number of reason that this does not fail. 可能有很多原因,这不会失败。

As stated in comments, the most likely is that windows is putting a large chunk of it in Virtual Memory (not RAM). 正如评论中所述,最有可能的是Windows将大部分内容放入虚拟内存(而不是RAM)中。

Another option (under some circumstances) is that the optimiser is cleaning up your list (maybe?) 另一种选择(在某些情况下)是优化者正在清理你的清单(可能?)

The best way to see exactly what is happening is to open task manager and switch to the Performance tab and look at the RAM monitors it uses. 查看确切情况的最佳方法是打开任务管理器并切换到“性能”选项卡,然后查看它使用的RAM监视器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM