Created
October 26, 2015 17:08
-
-
Save mmorearty/fa34c0f29abe454fd14b to your computer and use it in GitHub Desktop.
Memory-consumption test to accompany http://superuser.com/a/767491/94393
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
// Compile this with "cc malloc-bytes.c -o malloc-bytes" | |
// Run with e.g. "./malloc-bytes 1000000" (mallocs 1MB) | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char* argv[]) { | |
if (argc < 2) { | |
fprintf(stderr, "Usage: %s <bytes-to-allocate>\n", argv[0]); | |
exit(1); | |
} | |
size_t bytes = (size_t)atol(argv[1]); | |
char* buf = malloc(bytes); | |
int i; | |
for (i=0; i<bytes; i+=4096) { | |
buf[i] = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment