/* bigdata.c - how much can one malloc take, and where does it land. C89. usage: bigdata MB */ #include #include #include #include #include int main(int argc, char **argv) { long mb = argc > 1 ? atol(argv[1]) : 300, i, pg = sysconf(_SC_PAGESIZE); char *p = malloc(mb << 20); if (!p) { printf("malloc %ld MB: NULL, errno %d (%s)\n", mb, errno, strerror(errno)); return 1; } for (i = 0; i < (mb << 20); i += pg) p[i] = 1; printf("malloc %ld MB: %p .. %p, touched\n", mb, (void *)p, (void *)(p + (mb << 20) - 1)); return 0; }