I need to use this Kernel32 structure: NUMA_NODE_RELATIONSHIP
But the Reserved field is declared as: BYTE Reserved[20];
To declare the structure properly, is there a better way than declaring:
public struct NUMA_NODE_RELATIONSHIP
{
public UInt16 NodeNumber;
public BYTE Reserved1;
public BYTE Reserved2;
...
public BYTE Reserved20;
public GROUP_AFFINITY GroupMask;
}
or using:
[StructLayout(LayoutKind.Explicit)]
public struct NUMA_NODE_RELATIONSHIP2
{
[FieldOffset(0)]
public UInt16 NodeNumber;
// [FieldOffset(2)] // **
// public byte Reserved;
[FieldOffset(22)]
public GROUP_AFFINITY GroupMask;
}
** I'm not sure my code is ok... Here FieldOffset is a byte offset or multiple of OS word size (32 or 64 bits)? Does the WIN32 API pad align struct fields and if so, how? If both are padded or both are not padded, I'm fine, otherwise my code is bugged. That is not my main question. That insert is there only to mention that my code is not necessarily working as it is written. My main question is this one:
What is the best way to declare a pinvoke struct with an array in it? I wonder if both will be fine, which one is preferred and/or if there is a better way of declaring that struct because both way I used add artifacts that make it long to write and/or harder to understand.
intsize escapes them. Microsoft for instance doesn't care, the WINAPI talks about DWORD not int.