MyDevBank

MyDevBank

summaries and tech views for new developers C#,asp.net for web\mobile development,databases,iis6 and more.
Creating this site was an idea that popped up after some programing years, when you have to get back to the same things you all ready forgot, while new stuff is arriving to town. In this site you can find summaries on tech stuff im into, so for a stable wide base knowledge pyramid ,enjoy!!

Stack & Heap

Memory Allocation

The Common Language Runtime allocates memory for objects in two places:

  1. stack
  2. heap
The stack is a simple first-in last-out memory structure, and is highly efficient.
When a method is invoked,
  • the CLR bookmarks the top of the stack.
  • The method then pushes data onto the stack as it executes - "Push and execute"
  • When the method completes, the CLR just resets the stack to its previous bookmark - "Pop"
the heap is a random mix of objects.
Its advantage is that it allows objects to be allocated or deallocated in a random order. the heap requires the overhead of a memory manager and garbage collector to keep things in order.


Value and Reference Types

a value type will allocate in the Stack.
when declaring a var like int i = 0; into the stack and copying int j = i; we have two vars in the stack with values.
if we do j = 2; i still will be 0.

a reference type will allocate a reference to the Heap in the stack, when in the Heap allocated the object's content.
reference types are objects and classes fit good in here.

Person A= new Person(); A in the stack holds the location of the object content. a reference.
A.age = 15; the content changed to 15.
Person B = A; this is a COPY of the reference name B in the stack.
A.age = 20; A and B content in the heap will change to 20

Boxing
converting ValueTypes to Reference Types

Int32 x = 5;
object o = x; // Boxing
x = o; // UnBoxing
Comment | Related Tags

HOME| IIS6 pipeline| ASP.NET pipeline| Http Modules| Http Handlers| Caching| Web Services| Page Life Cycle| Ajax| Jquery| Session State
ViewState| SEO| Mobile Basics| Mobile Handsets| C# Modifiers| C# Keywords| N-Tier| Design patterns| Stack & Heap| WCF
Databases| Relational Model| functionalities| Stored procedures| fishmarket
MyDevBank
© 2010 All Rights Reserved