/******************************************************************************* * Test what the OS does, if there is no ram and cpu left. * Author: Nico Schottelius * Date: 4th of July 2001 * * * 5th of Decembre 2001: * added initialization of the new allocated ram. Without this 'feature' * Linux 2.4 has no problems. It is even possible to allocate 2000 MB RAM, * where only 128 MB is! (Linux gives you 'SoftRam'...) * ******************************************************************************/ #include #include #define lint long int lint add(lint last) { if(last == 0) return last; else if(last < 0) return -1; else return last + add(last -1); } int main ( void ) { char **uebervoll = NULL; int x = 1, a = 0; /* how many megs to allocate within one step */ int one_k = 1024; int one_meg = one_k * 1024; lint i = 0; uebervoll = (char **) realloc(uebervoll, (i+1) * sizeof(char *) ); for(i=0;;) { uebervoll = (char **) realloc(uebervoll, (i+1) * sizeof(char *)); if(uebervoll != NULL) { uebervoll[i] = (char *) malloc(x * one_meg * sizeof(char) ); /* init allocated ram */ for(a=0;a<(x*one_meg*sizeof(char));a++) uebervoll[i][a] = 'a'; if(uebervoll[i] != NULL) { i++; printf("%d MB RAM allocated\n",x * i); } } } }