I wrote a program, that allocates memory, and computes the size between adress of lowest, and highest pointer. I am suprised with results. When I start it, it takes 20mb of memory, 40, 60 ... 200, 220, 240,... 3000mb, 3020mb, and then suddenly bang, 262000 mb, and so on. Could somebody explain me why?
#include <iostream>
using namespace std;
int aaa;
int *max1=&aaa;
int *min1=&aaa;
void results(){
cout<<"min "<<min1<<endl;
cout<<"max "<<max1<<endl;
double mln= 1e6;
cout<<"min-max= "<<(max1-min1)/(1024*1024)<<"mb"<<endl;
}
void logic(int *c){
if(c>max1){
max1=c;
}
if(c<min1){
min1=c;
}
static int i;
i++;
if(i%800==0)
results();
}
int main(){
int *x;
int l=0;
while(l<=500000000){
l++;
x=new int[20000];
logic(&x[19999]);
}
}