Its still not worth risking treating memory on a chance. Vart was spot on. If you dice with memory allocation especially in C you are dicing with IT death.
Its still not worth risking treating memory on a chance. Vart was spot on. If you dice with memory allocation especially in C you are dicing with IT death.
Double Helix STL
Hmm, how can you use realloc sensibly then?
If you use a temp variable to store the return value of realloc, and it turns out to be NULL, what can you do, as that surely implies that there isn't enough memory left to do whatever you wanted to do and therefore the program may as well quit.
Unless I'm missing something...
The sensible thing to do would be to have your program handle the fact that memory is lacking (or that the realloc didn't work).
This could be done by informing the user, freeing everything and exiting, or doing something else to continue execution with the amount of memory you already have.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
Just a quick note on realloc. Memory allocation routnies costs alot ( in terms of processing time ). It's good practice to use realloc moderately, allocate a resonable amount of memory initially, and then increase it in steps, using realloc.
First there was God. He was quite lonely, so he created Dennis.
Dennis was unimpressed with God.
So, . . . God created Brian..........Khan Klatt
http://www.clifford.at/fun/GOD