#include #include int main(void) { size_t nbL = 100; size_t nbC = 500000000; printf("Tentative d'allocation pour %zu x %zu entiers\n", nbL, nbC); printf("soit %zu octets (environ %zu Go)\n", nbL * nbC * sizeof(int), (nbL * nbC * sizeof(int)) >> 30); int** ti =(int**) calloc(nbL, sizeof(int*)); if (ti != NULL) { int i = 0; while ((i < nbL) && ((ti[i] = (int*) calloc(nbC, sizeof(int))) != NULL)) { i++; printf("+"); } printf("\n"); if (ti[nbL - 1] == NULL) { printf("Allocation impossible a la ligne %d/%zu\n", i + 1, nbL); printf("Desallocation de ce qui avait ete alloue\n"); for (int j = 0; j < i; j++) { free(ti[j]); ti[j] = NULL; printf("-"); } printf("\n"); free(ti); ti = NULL; } } printf("\n"); if (ti != NULL) { printf("Allocation reussie\n"); } else { printf("Allocation avortee\n"); } if (ti != NULL) { for (int i = 0; i < nbL; i++) { free(ti[i]); ti[i] = NULL; } free(ti); ti = NULL; printf("Desallocation terminee\n"); } return 0; }