Marshal::SizeOf Method (Object^)
Returns the unmanaged size of an object in bytes.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- structure
-
Type:
System::Object^
The object whose size is to be returned.
| Exception | Condition |
|---|---|
| ArgumentNullException | The structure parameter is null. |
This method accepts an instance of a structure, which can be a reference type or a boxed value type. The layout must be sequential or explicit.
The size returned is the size of the unmanaged object. The unmanaged and managed sizes of an object can differ. For character types, the size is affected by the CharSet value applied to that class.
You can use the SizeOf method to determine how much unmanaged memory to allocate using the AllocHGlobal and AllocCoTaskMem methods.
The following example creates a managed structure, transfers it to unmanaged memory, and then transfers it back to managed memory. This example uses the SizeOf method to determine how much unmanaged memory to allocate.
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1