What size is a .NET object?

Posted by balajirnaukri-12656 under Interview Questions on 4/23/2012 | Points: 10 | Views : 1424 | Status : [Member] | Replies : 2
What size is a .NET object?

Each instance of a reference type has two fields maintained by the runtime - a method table pointer and a sync block. These are 4 bytes each on a 32-bit system, making a total of 8 bytes per object overhead. Obviously the instance data for the type must be added to this to get the overall size of the object. So, for example, instances of the following class are 12 bytes each:

class MyInt
{
...
private int x;
}

However, note that with the current implementation of the CLR there seems to be a minimum object size of 12 bytes, even for classes with no data (e.g. System.Object).

Values types have no equivalent overhead.

Thanks and Regards
Balaji.R
ASP.NET Devloper
Solve-IT corp



Responses

Posted by: GSM_GSV on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Balaji

Please post your questions in interviews section

---------------------------------------
Live the life you've dreamed

Regards
MADHU

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: balajirnaukri-12656 on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
yeah sorry accidently i did it

Thanks and Regards
Balaji.R
ASP.NET Devloper
Solve-IT corp

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response