I got a problem with the malloc function. The purpose of this program is to try to allocate memory to an extend when the system won't allocate memory anymore.
Code:int main ()Code:{ int * buffer; int counter; counter = 0; /*buffer = (int*) malloc (102400*sizeof(int));*/ buffer = (int *)malloc(sizeof(int)); *buffer = 1024; printf("buffer: %d\n", *buffer); while(buffer!=NULL) { counter++; *buffer = *buffer + 1024; printf("count: %d\n", *buffer); } if (buffer==NULL) { printf("Error allocating memory!\n"); exit (1); }
When I compile and run the code it keeps on going and it will eventually run in -(number). While it should give an error with the allocation of memory.
So I don't know what I did now, maybe someone else has a solution for it.



LinkBack URL
About LinkBacks




