c++ - Do I have more than 265GB memory on my 8GB RAM laptop? -
I wrote a program that allocates memory, and calculates the size between the lowest, and the highest indicator . I am surprised with the results when I start it, 20 memory storage, 40, 60 ... 200, 220, 240, ... 3000 MB, 3020 MB, and then suddenly bang, 262000 MB, and so on . Can anyone explain me?
#include & lt; Iostream & gt; using namespace std; Int aaa; Int * max1 = & amp; Aaa; Int * min1 = & amp; Aaa; Zero result () {cout & lt; & Lt; "Min" & lt; & Lt; Min1 & lt; & Lt; Endl; Cout & lt; & Lt; "Max" & lt; & Lt; Max1 & lt; & Lt; Andal; Double MLN = 1A6; Cout & lt; & Lt; "Min-max =" & lt; & Lt; (Max1-min1) / (1024 * 1024) & lt; & Lt; "Mb" & lt; & Lt; Endl; } Zero argument (int * c) {if (c> max1) {max1 = c; } If (c & lt; min1) {min1 = c; } Fixed int i; I ++; If (i% 800 == 0) the result (); } Int main () {int * x; Int l = 0; While (L & L; = 500000000) {l ++; X = new int [20000]; Logic (& amp; x [19999]); }}
compare (and consequently subtract) points that point to elements Not the same array is meaningless (pun intended)
You are making an arithmetic on unrelated addresses, what can be the result?
You are not comparing the lowest address of the lowest address in the allocated block, you are comparing the following address to see the highest address seen in 800 different storage allocations.
Consider all pile fragmentation (and potentially retrieval) that occur between all those calls. You can get positive, negative or zero as your difference.
If you are trying to determine, then there is a limit of piles, so this is a very random approach, because you have no guarantee to find before you get out of memory and accident. Are small and biggest addresses.
Consider also the effects of virtual memory and paging. With a modern implementation of virtual memory, you can address your process as a lot of memory in theory (I think), regardless of how much Ram (you have actually installed).
Also, see: Link to comments about virtual memory and.
Comments
Post a Comment