What is the size of an object reference in .NET? Does it vary between x86, x64, and/or AnyCPU compilation?
If it makes a difference, I'm interested in C#.
What is the size of an object reference in .NET? Does it vary between x86, x64, and/or AnyCPU compilation?
If it makes a difference, I'm interested in C#.
The reference itself is basically a pointer. 32 bits on a 32 bit OS, 64 bits on a 64 bit OS.
The size of the object that's referenced is more complicated.
For determining pointer size, you can use System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr))
, or sizeof(IntPtr)
in unsafe context.
Edit:
Or IntPtr.Size
.
An object reference is basically a pointer to the memory that contains the object's attributes. As such the reference is one processor word in length - 32 bits on 32 bit platforms and 64 bits on x64.