NET 中对象引用的大小是多少? 在 x86、 x64和/或 AnyCPU 编译之间是否有所不同?
如果有区别的话,我对 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.
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.
For determining pointer size, you can use System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)), or sizeof(IntPtr) in unsafe context.
System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr))
sizeof(IntPtr)
Edit:
Or IntPtr.Size.
IntPtr.Size