История изменений
Исправление MOPKOBKA, (текущая версия) :
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main() {
size_t i = 1 * 1024 * 1024 * 1024;
char *p = malloc(i);
for (size_t j = 1; j < 100; j++) {
p = realloc(p, i * j);
if (p == NULL) fprintf(stderr, "realloc() == NULL (%zu)\n", i * j);
else fprintf(stderr, "allocate %zu g\n", j);
memset(&p[i * (j - 1)], 0, i);
}
}
./a.out
allocate 1 g
allocate 2 g
allocate 3 g
allocate 4 g
allocate 5 g
allocate 6 g
allocate 7 g
allocate 8 g
allocate 9 g
allocate 10 g
allocate 11 g
allocate 12 g
allocate 13 g
allocate 14 g
allocate 15 g
allocate 16 g
allocate 17 g
allocate 18 g
allocate 19 g
allocate 20 g
allocate 21 g
allocate 22 g
allocate 23 g
allocate 24 g
allocate 25 g
allocate 26 g
allocate 27 g
allocate 28 g
allocate 29 g
allocate 30 g
allocate 31 g
allocate 32 g
allocate 33 g
allocate 34 g
allocate 35 g
allocate 36 g
allocate 37 g
allocate 38 g
Убито
Исходная версия MOPKOBKA, :
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main() {
size_t i = 1 * 1024 * 1024 * 1024;
char *p = malloc(i);
for (size_t j = 1; j < 100; j++) {
p = realloc(p, i * j);
if (p == NULL) fprintf(stderr, "realloc() == NULL (%zu)\n", i * j);
else fprintf(stderr, "allocate %zu g\n", j);
memset(&p[i * (j - 1)], 0, i);
}
}
./a.out
allocate 1 g
allocate 2 g
allocate 3 g
allocate 4 g
allocate 5 g
allocate 6 g
allocate 7 g
allocate 8 g
allocate 9 g
allocate 10 g
allocate 11 g
allocate 12 g
allocate 13 g
allocate 14 g
allocate 15 g
allocate 16 g
allocate 17 g
allocate 18 g
allocate 19 g
allocate 20 g
allocate 21 g
allocate 22 g
allocate 23 g
allocate 24 g
allocate 25 g
allocate 26 g
allocate 27 g
allocate 28 g
allocate 29 g
allocate 30 g
allocate 31 g
allocate 32 g
allocate 33 g
allocate 34 g
allocate 35 g
allocate 36 g
allocate 37 g
allocate 38 g
Убито