Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/resource.h>
#define MSIZE 10000
int main() {
int* a[MSIZE];
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
printf("Not allocated: %ld\n", usage.ru_maxrss);
for (int i = 0; i < MSIZE; i++)
a[i] = malloc(INT_MAX);
getrusage(RUSAGE_SELF, &usage);
printf("Allocated: %ld\n", usage.ru_maxrss);
for (int i = 0; i < MSIZE; i++)
free(a[i]);
getrusage(RUSAGE_SELF, &usage);
printf("Freed: %ld\n", usage.ru_maxrss);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment