views:

452

answers:

1

Is there any way to get the size of an instance (or the class I don't mind) in C#?

For example, I know in Delphi every object has a pointer to the Virtual Method Table of the class, a pointer for each interface it implements plus of course the fields of the class.

According to this basic object size is 12 bytes in x86, but, is there any "rule" to properly size it?

+2  A: 

It depends on what you are looking to do. If you are interested in finding out how big a type / object will be for the purpose of interop with native code, you can use Marshal.SizeOf(). Other than that, there is no definitive way to measure an object's size.

JaredPar