Last active
June 19, 2017 15:19
-
-
Save brunoczim/a521d46449fb9dcdba58bcd64c4d4b42 to your computer and use it in GitHub Desktop.
A small C program for testing the current memory limit.
This file contains hidden or 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 <string.h> | |
int main(int argc, const char **argv) { | |
size_t chunk = 0b1 << 10; | |
size_t interval = 0b1 << 15; | |
size_t i = 0; | |
char *ptr = malloc(chunk * (i + 1)); | |
while (ptr != NULL) { | |
memset(ptr + chunk * i, 0, chunk); | |
if (i % interval == 0) { | |
printf("Current allocated: %zu\n", chunk * i); | |
} | |
i++; | |
ptr = realloc(ptr, chunk * (i + 1)); | |
} | |
printf("Max memory allocated: %zu\n", chunk * i); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment