Marshal.SizeOf 方法

定义

返回类的非托管大小(以字节为单位)。

重载

名称 说明
SizeOf(Object)
已过时.

以字节为单位返回对象的非托管大小。

SizeOf(Type)
已过时.

返回非托管类型的大小(以字节为单位)。

SizeOf<T>()

返回非托管类型的大小(以字节为单位)。

SizeOf<T>(T)

返回指定类型的对象的非托管大小(以字节为单位)。

SizeOf(Object)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

注意

SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514

以字节为单位返回对象的非托管大小。

public:
 static int SizeOf(System::Object ^ structure);
[System.Obsolete("SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514")]
public static int SizeOf(object structure);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")]
public static int SizeOf(object structure);
public static int SizeOf(object structure);
[System.Runtime.InteropServices.ComVisible(true)]
public static int SizeOf(object structure);
[<System.Obsolete("SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514")>]
static member SizeOf : obj -> int
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")>]
static member SizeOf : obj -> int
static member SizeOf : obj -> int
[<System.Runtime.InteropServices.ComVisible(true)>]
static member SizeOf : obj -> int
Public Shared Function SizeOf (structure As Object) As Integer

参数

structure
Object

要返回其大小的对象。

返回

非托管代码中指定对象的大小。

属性

例外

参数 structurenull.

注解

此方法接受结构实例,该实例可以是引用类型或装箱值类型。 布局必须是顺序或显式布局。

返回的大小是非托管对象的大小。 对象的非托管和托管大小可能有所不同。 对于字符类型,大小受 CharSet 应用于该类的值的影响。

可以使用该方法 SizeOf 来确定使用 AllocHGlobalAllocCoTaskMem 方法分配多少非托管内存。

另请参阅

适用于

SizeOf(Type)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

注意

SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515

返回非托管类型的大小(以字节为单位)。

public:
 static int SizeOf(Type ^ t);
[System.Obsolete("SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515")]
public static int SizeOf(Type t);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")]
public static int SizeOf(Type t);
public static int SizeOf(Type t);
[<System.Obsolete("SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515")>]
static member SizeOf : Type -> int
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")>]
static member SizeOf : Type -> int
static member SizeOf : Type -> int
Public Shared Function SizeOf (t As Type) As Integer

参数

t
Type

要返回其大小的类型。

返回

非托管代码中指定类型的大小。

属性

例外

参数 t 是泛型类型定义。

参数 tnull.

注解

如果没有结构,则可以使用此方法。 布局必须是顺序或显式布局。

返回的大小是非托管类型的大小。 对象的非托管和托管大小可能有所不同。 对于字符类型,大小受 CharSet 应用于该类的值的影响。

另请参阅

适用于

SizeOf<T>()

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

返回非托管类型的大小(以字节为单位)。

public:
generic <typename T>
 static int SizeOf();
public static int SizeOf<T>();
static member SizeOf : unit -> int
Public Shared Function SizeOf(Of T) () As Integer

类型参数

T

要返回其大小的类型。

返回

泛型类型参数指定的 T 类型的大小(以字节为单位)。

注解

如果没有结构,则可以使用此方法。 布局必须是顺序或显式布局。

返回的大小是非托管类型的大小。 对象的非托管和托管大小可能有所不同。 对于字符类型,大小受 CharSet 应用于该类的值的影响。

适用于

SizeOf<T>(T)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

返回指定类型的对象的非托管大小(以字节为单位)。

public:
generic <typename T>
 static int SizeOf(T structure);
public static int SizeOf<T>(T structure);
static member SizeOf : 'T -> int
Public Shared Function SizeOf(Of T) (structure As T) As Integer

类型参数

T

参数的类型 structure

参数

structure
T

要返回其大小的对象。

返回

非托管代码中指定对象的大小(以字节为单位)。

例外

参数 structurenull.

注解

此方法接受结构实例,该实例可以是引用类型或装箱值类型。 布局必须是顺序或显式布局。

返回的大小是非托管对象的大小。 对象的非托管和托管大小可能有所不同。 对于字符类型,大小受 CharSet 应用于该类的值的影响。

可以使用 SizeOf<T>(T) 该方法来确定使用 AllocHGlobalAllocCoTaskMem 方法分配的非托管内存量。

适用于