How to know how much of memory has been allocated in stack and how much amount of memory is free??
How to know how much of memory has been allocated in stack and how much amount of memory is free??
Null pointer points to 0 or (void*)0?
Those are essentially equivalent. 0 is the value of NULL, the (void *) makes it compatible with pointers. Note however that this is C. In C++ 0 is compatible with all pointers.
[Note also that SOME systems may internally represent NULL as a different value, but it will still be false/zero when using such a pointer in a condition].
First of all, those are two different measures. Only certain systems (particularly DOS) would use "the memory between top of stack and end of data is heap" - in fact, even there's nothing saying that it HAS to be that way.
Second, there's no real good way to determine how much memory is free at any given time - you may be able to ask the OS, but even if you are given a number back from the OS, there's absolutely no guarantee that this number holds true when you get it back from the OS, never mind later on. Modern OS's are multitasking/multithreading, and another task may run at any given time, so what was free two microseconds ago, isn't now. Just like phoning the cinema and asking if there are tickets available for the latest movie - if they say yes, doesn't guarantee that tickets will be available when you get there. The only way to ensure that memory is available is to try to allocate it - like booking the tickets over the phone at the cinema - if it succeeds, then you have the memory, and you can use it. If it fails, then you are out of memory - do something else [usually stop, hopefully you can save what was going on without too much problem].
--
Mats
Last edited by matsp; 07-15-2008 at 02:34 AM.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.