What is the difference between the Heap and the Stack?

M

Ma Xiaoming

Dear ladies and gentlemen,

I don't understand what the difference between the Heap and the Stack
is. Could you please explain the difference between the both for me?

Thank you very much.

Best regards.
 
¿

¿ Mahesh Kumar

Here is the very good, clear and technical diff..Ma Xiaoming!!



Stack...

1. lives in RAM (random-access memory), but has direct support from the
processor via its stack pointer.

2. stack pointer is moved down to create new memory and moved up to release
that memory.

3. extremely fast and efficient way to allocate storage, second only to
registers.

4. stack is maily used for value types[ Ex : value datatypes in C# ].

5. This portion of the memory is not garbage collectible.



Heap...

1.lives in general-purpose pool of memory (also in the RAM area) where all
objects live.

2. the compiler doesn't need to know how much storage it needs to allocate
from the heap or how long that storage must stay on the heap.

3. Whenever we need to create an object, you simply write the code to create
it using new, and the storage is allocated on the heap

4. to put in simple terms heap memory is used for allocation of memory for
object types (where actual object is created )and only the heap part of the
memory is gargabe collectible (eligible for automatic garbage collection)



hope this will clear...



Mahesh

http://spaces.msn.com/members/cyberiafreak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top