Last active
November 17, 2021 21:29
-
-
Save dulimarta/c930fcc332c8aebedfe7a08809d7670d to your computer and use it in GitHub Desktop.
CS452 Lab10 - hugemem.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
const size_t GIGA = 1024*1024*1024; | |
int main() { | |
for (int k = 1; k <= 128; k++) { | |
char *p = malloc(k * GIGA); | |
if (p == NULL || errno != 0) { | |
perror("After malloc() failure"); | |
fprintf (stderr, "Failed at %d GBytes\n", k); | |
return -1; | |
} | |
free(p); | |
} | |
printf ("Max attempted allocation 128G\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment