I'm trying to measure the maximum resident set size and I found that you can do so with getrusage:
- https://linux.die.net/man/2/getrusage
- http://pubs.opengroup.org/onlinepubs/009695399/functions/getrusage.html
When I run this
#include <iostream>
#include<vector>
#include <sys/resource.h>
using namespace std;
int main(int argc, char* argv[]){
int who = RUSAGE_SELF;
struct rusage usage;
int ret = -1;
vector<int> v(1024);
ret = getrusage(who, &usage);
if (ret == 0) cout << usage.ru_maxrss << endl;
return 0;
}
I get the same value as I do when I comment the declaration of the vector.
Is there anything I'm doing wrong?
Thanks!
I have modified your code a bit to make sense for you for the data which is shown by the ru_maxrss element of rusage structure.
Here is my code
Each time getrusage() is called it allocates a different resident set size which is a few kB(approx 600-800) greater than the size allocated for the vector.
Some of the outputs of the above code are as follow

If I reduce the no. of elements in the vector to 1024000 the output is as follow