Blittable and Non-Blittable Types

Most data types have a common representation in both managed and unmanaged memory and do not require special handling by the interop marshaler. These types are called blittable types because they do not require conversion when passed between managed and unmanaged code.

The following types from the System namespace are blittable types:

The following complex types are also blittable types:

  • One-dimensional arrays of blittable types, such as an array of integers.
  • Formatted value types that contain only blittable types (and classes if they are marshaled as formatted types).

As an optimization, arrays of blittable types and classes containing only blittable members are pinned instead of copied during marshaling. These types can appear to be marshaled as In/Out parameters when the caller and callee are in the same apartment. However, these types are actually marshaled as In parameters and you must apply the InAttribute and OutAttribute attributes if you want to marshal the argument as an In/Out parameter.

Non-blittable types have different or ambiguous representations in managed and unmanaged languages. These types might require conversion when they are marshaled between managed and unmanaged code. For example, managed strings are non-blittable types because they can have several different unmanaged representations, some of which can require conversion.

The following table lists non-blittable types from the System namespace. Delegates, which are data structures that refer to a static method or to a class instance, are also non-blittable.

Non-blittable type Description
System.Array Converts to a C-style array or a SAFEARRAY.
System.Boolean Converts to a 1, 2, or 4-byte value with true as 1 or -1.
System.Char Converts to a Unicode or ANSI character.
System.Class Converts to a class interface.
System.Object Converts to a variant or an interface.
System.Mdarray Converts to a C-style array or a SAFEARRAY.
System.String Converts to a string terminating in a null reference (Nothing in Visual Basic) or to a BSTR.
System.Valuetype Converts to a structure with a fixed memory layout.
System.Szarray Converts to a C-style array or a SAFEARRAY.

Class and object types are supported only by COM interop. For corresponding types in Visual Basic .NET, C#, and the Managed Extensions for C++, see the Introduction to the .NET Framework Class Library.

See Also

Default Marshaling Behavior | Memory Management | Directional Attributes | Copying and Pinning | Default Marshaling for Arrays | Default Marshaling for Boolean Types | Default Marshaling for Characters | Default Marshaling For Classes | Default Marshaling for Delegates | Default Marshaling for Objects | Default Marshaling for Strings | Default Marshaling for Value Types