Skip to content

Instantly share code, notes, and snippets.

@nelhage
Created March 30, 2012 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelhage/2253262 to your computer and use it in GitHub Desktop.
Save nelhage/2253262 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#define NALLOC (1 << 10)
#define ALLOCSZ (1 << 12)
int main(void) {
void *buffers[NALLOC];
int i;
char cmdline[1024];
snprintf(cmdline, sizeof(cmdline), "ps --no-headers -o rss %d", getpid());
for (i = 0; i < NALLOC; i++)
buffers[i] = malloc(ALLOCSZ);
printf("Allocated memory...\n");
system(cmdline);
malloc(10);
for (i = 0; i < NALLOC; i++)
free(buffers[i]);
printf("Freed memory...\n");
system(cmdline);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment