Hi
What is the difference between Heap and Stack?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 20, 2011, 5:04 AM
Sam HobbsPosted Nov 20, 2011, 4:12 AM
Prabhu RajaPosted Nov 19, 2011, 6:31 AM
C# Heap(ing) Vs Stack(ing) in .NET: Part I, II, III and IV
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034PM/csharp_memory.aspx
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory2B01142006125918PM/csharp_memory2B.aspx
http://www.c-sharpcorner.com/UploadFile/rmcochran/chsarp_memory401152006094206AM/chsarp_memory4.aspx
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory_401282006141834PM/csharp_memory_4.aspx
Vineet Kumar SainiPosted Nov 19, 2011, 5:09 AM
The difference betweeb Heap and Stack are as follows
when you use new or malloc() the memory is normally allocated from the heap. When you allocate an object within a function, it goes on the stack.
Heap memory stores all instances or attributes, constructors and methods of a class/object.
Stack memory is referred as temporary memory.
Heap memory is referred as permanent memory.
The heap (also known as the free store) is a large pool of memory used for dynamic allocation.
Stack is used for local variables.
Heap is used for dynamic memory allocation.
Stack is maily used for value types[ Ex : value datatypes in C# ].
Datta KharadPosted Nov 19, 2011, 12:47 AM
Heap and Stack:-
Procedural programming languages that let you to create variables dynamically at run-time use two different areas of Ram for holding variables;. the stack and the heap. The heap is basically all unallocated memory.
Satyapriya NayakPosted Nov 19, 2011, 12:29 AM
Stack
Stack memory stores variable types in address' in memory, these variables in programming are called local variables and are often stored for short amounts of time while a function/method block uses them to compute a task.
Once a function/method has completed its cycle the reference to the variable in the stack is removed.
Heap
Heap memory stores all instances or attributes, constructors and methods of a class/object.
Comparison
A Heap reference is also stored in Stack memory until the life cycle of the object has completed. Inside the Heap reference all the the contents of the object are stored whereas with a local variable only the variable contents are stored in the stack.
Refer the below link also
http://www.programmerinterview.com/index.php/data-structures/difference-between-stack-and-heap/
Thanks