Pages

Sunday, May 12, 2013

memory architecture in c#(important)

Ram partition:

Ram will be partioned broadly into the below main categories
1.Stack
2.Heap
3.Data segment
4.Readonly segment
5.code segment
Note: Here out of 5 types mainly  3 part will be discuss bec stack ,heap and code segment are cover all the 
explantion.

example:

     {
      student s=new student();  // s is a local variable(will be avalble in the current method)
      int r=s.GetAge();
      Response.Write(r);
      }
}
public class student
{
      public int age=24;    // class variable
      public string name="Rakesh"; // class variable
      public int GetAge();
      {
          int x=1;
          return age;
      }
}

Explanation:

->Stack segment contains all local variables and all object
->  Reference type will be declared in the heap memory
->All the methods will be loaded in the code segment.

Note:

Method will be loaded into the code segment only when you call the method.In the above program when clr comes to the GetAge() method calling syntax then it loads the method into the code segment and execute the code in the method by creating the local variable in the stack or heap depending on the value type and referance type.
-> All cocal variable will be placed in the stack but data of those variable will be placed either in stack or heap depnding on the value type or referance type

Note:

Once method execution is compiled all the local variable present in those method will be deleted from the respective memory locations automaticall






No comments:

Post a Comment