|
From: Adam J. <aj...@i-...> - 2007-07-17 18:13:46
|
>>Jonathan Wrote: >>However, Adam you are wrong about the allocation of char str[10]: this data will be allocated on the stack, along with other local variables. You can't check whether it failed or >>not: if there's anough room, ok, if not, the program will have already crashed (stack overflow) before you can do anything (this is why we use malloc() for large amounts of >>memory, which indeed needs checking) When you declare Char str[10], you do create it on the stack. But I was suggesting that he create it on the heap with the Malloc() function. Please reread what I posted, it is listed below again: >>Adam Wrote: >>You also assume which is not very good >>that the system will allocate a char str[10] without checking to see if it >>can do it with a malloc first. On memory allocations you need to check >>first, and if it fails exit your program gracefully. Maybe bad wording, but the fact remains that if you are going to allocate memory, to be safe do it on the heap (using malloc()) instead of the stack. That is what I was suggesting. I hope this clears up any miscommunications on my part..... |