Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Created June 29, 2017 13:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Kwpolska/12f61143a8d9d222b279646694b7f049 to your computer and use it in GitHub Desktop.
#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