Last active
December 16, 2015 18:59
-
-
Save gebi/5481373 to your computer and use it in GitHub Desktop.
Short example program to show linux memory allocation behaviour (memory is only allocated on first access, in this example program after you press enter) Test with: gcc -O0 -Wall static_mem_test.c -o static_mem_test && /usr/bin/time --verbose ./static_mem_test
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 <unistd.h> | |
static char staticfoo[80*1024*1024]; // = {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}; | |
#define WRITE(Str) write(1, Str, sizeof(Str)) | |
int main() | |
{ | |
char in; | |
int i; | |
for(i=0; i<sizeof(staticfoo); i++) { | |
in = staticfoo[i]; | |
if(in != 0) | |
return(1); | |
} | |
WRITE("pause..."); | |
read(0, &in, 1); | |
for(i=0; i<sizeof(staticfoo); i++) | |
staticfoo[i] = 0; | |
WRITE("pause..."); | |
read(0, &in, 1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment