Saturday 9 January 2016

What is Object in c# and its memory allocation

* Object in c# is a pointer to the memory block that is allocated for a class.
* an object contains the reference of memory block that are created by new class_name()
* Only those things comes into object scope that member variable or function of class
* Static variable or function is not the part of object.


  in c# a class is a reference type and when we declare any variable for a class then it is called a      instance
ex. 

Class Test
{
 Test test;//instance variable
 Test test1=new Test();//test-->object
}

*for a object the memory allocated into stack and provided space of 4 bite in c# and for a class memory allocated into heap and its address stored into stack and that stack block named by the object variable.


   
But if you are talking about c++
  
  in c++ class is a value type that why an object does not need to have a memory block in heap
  ex.

  # include <iostream.h>

Class Test
{
int eid;
  public:
          void display()
             {
               eid=201;
               cout <<"hello";
             }
}

void main()
{
  Test test;
  test.display();//correct
  //we can also do
 Test *test;
 test->display();//error , to remove the error we need to assign the memory block for class as //Test *test=new Test();
}

No comments:

Post a Comment

Contact Us:

Email:

Vinodkumar434@gmail.com,
vinodtechnosoft@gmail.com

Skype Name:

vinodtechnosoft