Getting size of class

I'm trying to determine shallow size of some class, I mean corresponding System.Type's instance size. Unfortunately I've got only ClassID of given class and using GetObjectSize function with ClassID as a parameter causes crash. Maybe there is a way to obtain ObjectID of needed System.Type's instance?
Thanx
[322 byte] By [VitalyPimenov] at [2008-3-1]
# 1
If this is for interop, and you need the size that the object will be when it is marshalled to unmanaged code, then you can use:


Marshal.SizeOf( typeof( <classname> ) );

280Z28 at 2007-9-9 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 2
No, I'm using .NET Profiling API 2.
VitalyPimenov at 2007-9-9 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 3
I've toyed with methods for getting the size of simple objects (as of yet I have found no good way to do this for more complex types short of marking them as MBR and using the method mentioned above). my interest has been in pinning the object and zeroing its memory (this need has largely been eliminated by the SecureString class)

here is what I have for simple types (hopefully it points you in the right direction)
http://stand__sure.aspfreeserver.com/sizeof/utility.vb.html

stand__sure at 2007-9-9 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 4

The ICorProfilerInfo2::GetClassLayout function takes a ClassID and returns both the layout of the class and its size.

.NET Development

Site Classified