A number of things might be happening...
- compiler the compiler may be optimizing the memory allocation out (since nothing is actually done with it)
- operating system the memory may not be allocated by the operating system since the pages aren't written to
- sampling the resource usage may not show up on your system monitor since your program exits immediately after allocating the memory
So, to eliminate these potential causes you could write something like this...
#include <iostream>
int main(int argc, char* argv[]) {
int x,y;
std::cin >> x;
int* m = new int[x];
for (int i = 0; i < x; i++)
m[i] = i;
std::cin >> y;
std::cout << m[y] << std::endl;
return 0;
}
Then, you should be able to check memory usage before you enter the y
value. I'm not sure what operating system you're using, but you should see the image size and the resident memory of the program increase roughly by 4x
bytes.