Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <inttypes.h>
- #include <stdint.h>
- #define MEGABYTE 1024*1024
- static uint64_t getTotalSystemMemory()
- {
- long pages = sysconf(_SC_AVPHYS_PAGES);
- long page_size = sysconf(_SC_PAGE_SIZE);
- return pages * page_size / MEGABYTE;
- }
- int main(int argc, char *argv[])
- {
- void *myblock = NULL;
- int count = 0;
- while (1)
- {
- myblock = (void *) malloc(MEGABYTE);
- if (!myblock) break;
- printf("Currently allocating %d MB\n", ++count);
- printf("Free memory: %" PRId64 " MB\n", getTotalSystemMemory());
- nanosleep(1000 * 1000 * 2);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement