.NET中的对象引用有多大?

时间:2022-03-07 14:32:08

What is the size of an object reference in .NET? Does it vary between x86, x64, and/or AnyCPU compilation?

.NET中对象引用的大小是多少?它是否在x86,x64和/或AnyCPU编译之间有所不同?

If it makes a difference, I'm personally interested in C#.

如果它有所作为,我个人对C#感兴趣。

3 个解决方案

#1


61  

The reference itself is basically a pointer. 32 bits on a 32 bit OS, 64 bits on a 64 bit OS.

引用本身基本上是一个指针。 32位OS上为32位,64位OS上为64位。

The size of the object that's referenced is more complicated.

引用的对象的大小更复杂。

#2


17  

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。

#3


14  

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.

对象引用基本上是指向包含对象属性的内存的指针。因此,引用的长度为一个处理器字 - 32位平台上为32位,x64上为64位。

#1


61  

The reference itself is basically a pointer. 32 bits on a 32 bit OS, 64 bits on a 64 bit OS.

引用本身基本上是一个指针。 32位OS上为32位,64位OS上为64位。

The size of the object that's referenced is more complicated.

引用的对象的大小更复杂。

#2


17  

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。

#3


14  

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.

对象引用基本上是指向包含对象属性的内存的指针。因此,引用的长度为一个处理器字 - 32位平台上为32位,x64上为64位。