简体   繁体   中英

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.

After calculating the result I decided to count the total amount of numbers inside this final 3d vector and it was: 1386502951

that means that the total amount of memory needed to store this vector is at least 1386502951*4 bytes = 5.16512599 GB

however my RAM memory is only 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. A quick Google Dance should provide you with a significant number of links on the subject.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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