out_of_memory.c 345 B

12345678910111213141516171819
  1. /* Let's see how much memory Linux lets us allocate. */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int main(void) {
  5. char *ptr = NULL;
  6. size_t size = 1;
  7. while (1) {
  8. printf("0x%zx\n", size);
  9. ptr = realloc(ptr, size);
  10. if (ptr == NULL) {
  11. break;
  12. } else {
  13. size <<= 1;
  14. }
  15. }
  16. }