#include <stdio.h>
#include <stdlib.h>
int main()
{
char *p = NULL;
for (long long int i = 1; i < 100000000L; i += 100000)
{
long long int size = 10000 * i;
p = (char*)malloc(size);
if (p != NULL)
{
printf("Allocate: %llu bytes\n", size);
free(p);
}
else
{
printf("Cannot allocate size: %llu bytes\n", size);
break;
}
}
return 0;
}
/*
run:
Allocate: 10000 bytes
Allocate: 1000010000 bytes
Allocate: 2000010000 bytes
Allocate: 3000010000 bytes
Allocate: 4000010000 bytes
Allocate: 5000010000 bytes
Allocate: 6000010000 bytes
Allocate: 7000010000 bytes
Allocate: 8000010000 bytes
Allocate: 9000010000 bytes
Allocate: 10000010000 bytes
Allocate: 11000010000 bytes
Allocate: 12000010000 bytes
Allocate: 13000010000 bytes
Allocate: 14000010000 bytes
Allocate: 15000010000 bytes
Allocate: 16000010000 bytes
Allocate: 17000010000 bytes
Allocate: 18000010000 bytes
Allocate: 19000010000 bytes
Allocate: 20000010000 bytes
Allocate: 21000010000 bytes
Allocate: 22000010000 bytes
Allocate: 23000010000 bytes
Cannot allocate size: 24000010000 bytes
*/