Stack 'n Heap

Heap is a new born child, who's memory space is quite empty and thus large, whereas Stack is an old man.
The story about the old man Stack and the new born Heap is quite interesting. Both of them have good and poor qualities as well.

Well Stack knows to take care of himself. He knows how much he can contain and as well knows how to clean himself up once he finishes some task. The problem is that he is too old. He cannot remember many things together. So he only allows intake of information on a fixed count. Once he thinks he is full, he takes no more. But the work we need to do to make him forget those information is automatic. He himself forgets everything once the task is over.

The above inference is very well easy to understand. The old man is the Stack memory and the information he intakes is the stack variables.

Now consider the newborn Heap. Heap is in no sense automatic. He needs a babysitter for everything. He has a larger memory capacity as he is empty minded. Also does he not forget things easily unless and untill he is brainwashed. His memory is a little slower as he is only learning to use it. The brainwashing process is a serious one as if left untouched after use, the memory stays there forever and will not even be used for any other purposes.

Here the newborn is the Heap memory and the babysitter is the CPU which is controlled by the user. System functions are used to manipulate the heap memory. The heap memory should be freed or else the memory leak condition occurs, where the memory wont be used for other processes too. It is a slower type of memory than Stack but a larger one.

More of a professional point of view data can be read from here.

- all information is stolen from different websites.

Comments

Popular Posts