Blittable and Non-Blittable Types

Updated: February 2010

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 they are passed between managed and unmanaged code.

Return values from platform invoke calls must be blittable types. Platform invoke does not support non-blittable return types.

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. However, a type that contains a variable array of blittable types is not itself blittable.

  • Formatted value types that contain only blittable types (and classes if they are marshaled as formatted types). For more information about formatted value types, see Default Marshaling for Value Types.

Object references are not blittable. This includes an array of references to objects that are blittable by themselves. For example, you can define a structure that is blittable, but you cannot define a blittable type that contains an array of references to those structures.

As an optimization, arrays of blittable types and classes that contain 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.

Some managed data types require a different representation in an unmanaged environment. These non-blittable data types must be converted into a form that can be marshaled. For example, managed strings are non-blittable types because they must be converted into string objects before they can be marshaled.

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 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 2005, C#, and C++, see the .NET Framework Class Library Overview.

Other Resources

Date

History

Reason

 

February 2010

Clarified that return types must be blittable.

 

Customer feedback.

转载于:https://www.cnblogs.com/MayGarden/archive/2010/04/18/1714735.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值