Marshals data from a managed object to an unmanaged block of memory.
Assembly: mscorlib (in mscorlib.dll)
[<ComVisibleAttribute(true)>] static member StructureToPtr : structure:Object * ptr:IntPtr * fDeleteOld:bool -> unit
- Type: System.Object
A managed object that holds the data to be marshaled. This object must be a structure or an instance of a formatted class.
- Type: System.IntPtr
A pointer to an unmanaged block of memory, which must be allocated before this method is called.
structure is a reference type that is not a formatted class.
structure is a generic type.
If structure is a value type, it can be boxed or unboxed. If it is boxed, it is unboxed before copying.
copies the contents of structure to the pre-allocated block of memory that the ptr parameter points to. If structure contains reference types that marshal to COM interface pointers (interfaces, classes without layout, and System.Object), the managed objects are kept alive with reference counts. All other reference types (for example, strings and arrays) are marshaled to copies. To release these managed or unmanaged objects, you must call the Marshal.DestroyStructure method before you free the memory block.
If you use the method to copy a different instance to the memory block at a later time, specify true for fDeleteOld to remove reference counts for reference types in the previous instance. Otherwise, the managed reference types and unmanaged copies are effectively leaked.
The overall pattern for using is as follows:
On the first call to the method after a memory block has been allocated, fDeleteOld must be false, because there are no contents to clear.
Specify true for fDeleteOld only if the block contains valid data.
If you copy a different instance to the memory block, and the object contains reference types, fDeleteOld must be true to free reference types in the old contents.
If the object contains reference types, you must call the DestroyStructure method before you free the memory block.
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.