-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: IAmUnknownReference
Message 4 in Discussion


To talk about the difference between the Stack and the Heap, we will have to dig into 
one of the basic functionalities of the framework - CTS. The Common Type System in 
.NET distinguishes between two basic categories of types - value and reference types. 
The fundamental difference between these two categories lies in how they are stored in 
memory. .NET uses two different physical blocks of memory to store data � the stack 
and the managed heap.  
The stack stores data on a First In, Last Out (FILO) basis. Value types always take up 
a predefined number of bytes of memory. for example. an int will always take up four 
bytes, whereas the number of bytes taken up by a string will vary depending on the 
length of the string. when a value-type variable is declared, the appropriate amount 
of memory is allocated on the stack (except for value-type members of reference types, 
such as an int field of a class or something like that), and this space in memory is 
used to store the value held by the variable. .NET maintains a stack pointer which 
contains the address of the next available memory location on the stack. when a 
variable goes out of scope, the stack pointer is moved back by the number of bytes 
occupied by the freed variable, so that it still points to the next available address. 
 
Reference variables also make use of the stack, but in this case the stack only 
contains a reference to another memory location, rather than an actual value. This 
location is an address on the managed heap. As with the stack, a pointer is maintained 
which contains the address of the next free location on the heap. However, the heap is 
not FILO-based � because references to objects can be passed around within a program, 
say as arguments to method calls. Objects on the heap do not go out of scope at a 
predetermined point in the program. In order to free up memory allocated on the heap 
once it is no longer required, .NET has an inbuilt functionality called garbage 
collection. The garbage collector recursively examines all the object references in 
the application; the memory used by any object to which there are no active 
references, and can be reclaimed. To do this, the garbage collector shifts all the 
objects in subsequent memory locations down to occupy the unused space. 
Wonderfully designed implementation of the memory management right ! 

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to