Skip to content

Instantly share code, notes, and snippets.

@dulimarta
Last active November 17, 2021 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dulimarta/c930fcc332c8aebedfe7a08809d7670d to your computer and use it in GitHub Desktop.
Save dulimarta/c930fcc332c8aebedfe7a08809d7670d to your computer and use it in GitHub Desktop.
CS452 Lab10 - hugemem.c
#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