#include #include #include #include #ifdef _WIN32 #include #define sleep_ms(ms) Sleep(ms) #else #include #define sleep_ms(ms) usleep((ms) * 1000) #endif int MyNum; int times_iterated; int main() { const size_t CHUNK_SIZE = 500 * 1024 * 1024; size_t total = 0; while (1) { void *chunk = malloc(CHUNK_SIZE); if (!chunk) { printf("Malloc failed at %zuMB\n", total / 1024 / 1024); break; } memset(chunk, 0xAA, CHUNK_SIZE); total += CHUNK_SIZE; printf("Allocated: %zuMB\n", total / 1024 / 1024); sleep_ms(500); } return 0; }