I'm trying to monitor (with the system monitor) the total memory dynamically allocated by a snipped (for whatever reasons: I know, it sounds academic). Here's what I use (I know I'm not deallocating, and that the code is ugly).
#include <iostream>
#include <thread>
#include <cstdint>
using namespace std;
int main()
{
long long unsigned j = 0;
while(true)
{
int * pt = new int32_t[250 * 1000 * 10]; //10MB
static long long unsigned int m2GB = 200; //loop rounds needed to allocate 2GB
j++;
if(j % 10 == 0) //100MB per 100MB
{
cout << (j*10) << "MB allocated" << endl;
this_thread::sleep_for(100ms);
}
if(j >= m2GB)
break;
}
cout << "Type sth to close" << endl;
cin >> j; //blocking
}
Thing is... I don't even see a spike with this code, while, if I'm not mistaken, it should allocate up to 2GB of memory.
... what am I doing wrong ?