I am a newbee in C
I wanted to know the max memory allowed by an application. So I wrote a little program like the following.
I have a machine with 16GB total memory and 2GB is used and 14GB is free. I expected this program to stop around 14GB, but it runs forever.
Want am I doing wrong here?
#include <stdlib.h>
#include <stdio.h>
int main(){
long total = 0;
void* v = malloc(1024768);
while(1) {
total += 1024768;
printf ( "Total Memory allocated : %5.1f GB\n", (float)total/(1024*1024768) );
v = realloc(v, total);
if (v == NULL) break;
}
}
Edit: running this program on CentOS 5.4 64 bit.