Stack Vs Heap
Let's suppose there is nothing on the stack to begin with. One of the functions either the calling function or the called function depending on the calling convention would start a stack.
Lets take a very simple C / C++ program to see how things would work.
So the first thing compiler needs to do ( In terms of Stack Memory Allocation ) is pass the variable 4 to the called function.
So it would Push 4 into the Stack and advance the stack pointer to the Next Location and call the function
Heap consists of memory that can be allocated at run time and its something like a pool of memory from which you can request some chunk of it. It is independent of the function making a request and as your program does not take care of cleaning it up it's the programmer's job to deal with heap memory. The size of objects allocated on the heap is often not known to the compiler - therefore the programmer must allocate and release the memory specifically.
Re: Stack Vs Heap
Nominate this article for Article of the month for February 2009
|All times are GMT +5.5. The time now is 15:35.|