Failing to understand getrusage()
Nick Barnes
Nick.Barnes at pobox.com
Thu Mar 2 23:50:33 UTC 2006
At 2006-03-02 22:24:17+0000, Nik Clayton writes:
> I'm failing to understand how getrusage() works, which is a bit perplexing,
> because it doesn't seem like it would be terribly complicated.
ru_maxrss is the maximum resident set size, not the heap size.
malloc(big) doesn't grow the resident set. Touching the memory you
have allocated will grow the resident set. Try this:
getrusage(RUSAGE_SELF, &ru);
printf("%lu\n", ru.ru_maxrss);
p = malloc(SIZE);
assert(p)
getrusage(RUSAGE_SELF, &ru);
printf("%lu\n", ru.ru_maxrss);
for (i=0; i<SIZE; ++i) {
p[i] = 0;
}
getrusage(RUSAGE_SELF, &ru);
printf("%lu\n", ru.ru_maxrss);
Nick B
More information about the freebsd-stable
mailing list