Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2010 16:09
Show Gist options
  • Save anonymous/519232 to your computer and use it in GitHub Desktop.
Save anonymous/519232 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/sysinfo.h>
int main()
{
struct sysinfo sinfo;
sysinfo(&sinfo);
printf("total: %lu (%luMB), free: %lu (%luMB)\n", \
sinfo.totalram, (sinfo.totalram>>10)>>10, \
sinfo.freeram, (sinfo.freeram>>10)>>10);
while(1)
{
void * dontcare = malloc((32<<10)<<10); // 32MB
memset(dontcare, 0x1, (32<<10)<<10);
sysinfo(&sinfo);
printf("free: %lu (%luMB)\n", \
sinfo.freeram, (sinfo.freeram>>10)>>10);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment