G
Guest
what is the difference between a heap and a stack?
Terry Burns said:They are both memory which is used to store objects. The stack by default
only stores Value types like Struct and Integers, whereas the Heap is used
to allocate memory for reference types.
shine said:what is the difference between a heap and a stack?
Gino Cerone said:When an application is opened Windows allocates the full 32 bit address
space (4 gigs) of memory. (this is theoretical and Windows memory manager
maps from the actual memory to the 32 bit memory space) It sub-divides
this
into two parts, the Stack and Heap. The stack holds the declared named
varibles. In the case of a primative data type like 'byte' it holds the
value,
byte mybyte;
mybyte = 125;
In the case of instantiating a class, the declared name varible is writen
to
the stack. The instaniated Object in writen to the Heap. The value of the
varible in the stack holds the address space of the Object in the Heap.
sqlconnection myconnection; (declares the varible myconnection of type
sqlconnection in the stack. If you tried to use myconnection
now you would get a null
reference error because there isn't a memory address in the value yet.)
myconnection = new sqlconnection; (this line instantiates the class
'sqlconnection' into an Object in the Heap, and enters the address
of the Object in
the value for myconnection. myconnection becomes the pointer that
references
the Object
'sqlconnection' in the Heap.)
is not completely true, the compiler will not allow you to use ansqlconnection myconnection; (declares the varible myconnection of type
sqlconnection in the stack. If you tried to use myconnection
now you would get a null
reference error because there isn't a memory address in the value yet.)
Gino Cerone said:The information that I wrote was abstracted from this link.
http://www.softec.uni-duisburg-essen.de/C15/(C) C und das NET-Framew
ork%20(v/Document%20Library/CSharp_06_MemoryManagement.pdf
Which was writen by Dr. Stefan Eicker, who holds a PHD in computer
science,
and is a University professor and head of software engineering at the
University of Essen Germany. So it is ( according to you) Dr. Stefan
Eicker
who is simplistic and wrong.
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.