DWORD 是 uint,WORD 是 ushort。
[StructLayout(LayoutKind.Sequential)]
struct CACHE_DESCRIPTOR
{
public byte Level;
public byte Associativity;
public ushort LineSize;
public uint Size;
public PROCESSOR_CACHE_TYPE Type;
}
enum PROCESSOR_CACHE_TYPE
{
Unified = 0,
Instruction = 1,
Data = 2,
Trace = 3,
}
union 是具有Explicit 布局和FieldOffset 的结构。
[StructLayout(LayoutKind.Sequential)]
struct SYSTEM_LOGICAL_PROCESSOR_INFORMATION
{
public UIntPtr ProcessorMask;
public LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
public ProcessorRelationUnion RelationUnion;
}
[StructLayout(LayoutKind.Explicit)]
struct ProcessorRelationUnion
{
[FieldOffset(0)] public CACHE_DESCRIPTOR Cache;
[FieldOffset(0)] public uint NumaNodeNumber;
[FieldOffset(0)] public byte ProcessorCoreFlags;
[FieldOffset(0)] private UInt64 Reserved1;
[FieldOffset(8)] private UInt64 Reserved2;
}
[StructLayout(LayoutKind.Sequential)]
struct CACHE_DESCRIPTOR
{
public byte Level;
public byte Associativity;
public ushort LineSize;
public uint Size;
public PROCESSOR_CACHE_TYPE Type;
}
enum LOGICAL_PROCESSOR_RELATIONSHIP : uint
{
ProcessorCore = 0,
NumaNode = 1,
RelationCache = 2,
}
ULONGLONG 是 UInt64。它将结构与 8 字节边界(24 字节)对齐。正如 David 在 cmets 中指出的那样,它是必需的,并且由于某种原因,Microsoft Interop 库中缺少它。
更新:添加了缺失的结构和指向 Microsoft Research 的 Windows 互操作库的链接。
来源:WindowsInteropLib/Kernel32.cs