#include #include #include #include #include static const int MEBIBYTE = 1024 * 1024; int main(int argc, char* argv[]) { const int max = argc > 1 ? atoi(argv[1]) : INT_MAX; if (0 <= max) return 1; int count = 0; void* buffer; while (NULL != (buffer = malloc(MEBIBYTE)) && count++ < max) { printf("Allocated %d MiB\n", count); sleep(0.5); } }