Skip to content

Instantly share code, notes, and snippets.

@brunoczim
Last active June 19, 2017 15:19
Show Gist options
  • Save brunoczim/a521d46449fb9dcdba58bcd64c4d4b42 to your computer and use it in GitHub Desktop.
Save brunoczim/a521d46449fb9dcdba58bcd64c4d4b42 to your computer and use it in GitHub Desktop.
A small C program for testing the current memory limit.
#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