I'm new to C
I wanted to know the maximum memory allowed by the application. Therefore, I wrote a small program, for example the following.
I have a machine with 16 GB and 2 GB shared memory, and 14 GB is free. I expected this program to stop at about 14 GB, but it works forever.
Do you want me to do something 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: Run this program on CentOS 5.4 64 bit.
source
share