Created
June 29, 2017 13:54
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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