互操作填充 [英] Interop padding
问题描述
你好.我正在尝试定义 MIB_IPNET_TABLE2 以及来自C#的互操作的相关结构.现在文档说:
Hello. I am trying to define the MIB_IPNET_TABLE2 and related structures for interop from C#. Now the documentation says:
MIB_IPNET_TABLE2 结构可能包含填充,用于在 NumEntries 成员和第一个 MIB_IPNET_ROW2 数组条目中的 表成员.对齐之间也可能存在填充 表成员中的 MIB_IPNET_ROW2 阵列条目.任何访问 MIB_IPNET_ROW2 数组条目应假定可能存在填充.
The MIB_IPNET_TABLE2 structure may contain padding for alignment between the NumEntries member and the first MIB_IPNET_ROW2 array entry in the Table member. Padding for alignment may also be present between the MIB_IPNET_ROW2 array entries in the Table member. Any access to a MIB_IPNET_ROW2 array entry should assume padding may exist.
好吧..对我来说意味着什么?什么时候有填充,什么时候没有?我应将任何属性应用于结构或成员以由编组器处理吗?还是应该在C#中处理?
Okay, so.. what does it mean for me? When there is a padding and when there is not? Is there any attribute I should apply to the struct or members to have it handled by the marshaller? Or how is this supposed to be handled in C#?
感谢您的任何提示或见解!
Jan
Thanks for any hints or insight!
Jan
推荐答案
用于对齐的填充意味着,大于1个字节的类型将不会在4个字节的两组之间分散.我不知道该如何解释"这个,但我会尽力让您理解:
The padding for alignment means that a type that is larger than 1 byte will not be spread between two groups of 4 bytes. I don't know how to "explain" this, but I'll try to make you understand:
如果您声明以下结构:
typedef struct _S {
char a;
char b;
char c;
int d;
} S
这篇关于互操作填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!