我正在尝试使用 Windows 7 上的 C# 3.5 Windows 服务应用程序中的 GetSystemInfo() 获取分配粒度大小。但是,从调用返回时,SYSTEM_INFO 结构在 dwAllocationGranularity 中始终为 0(其他字段已填充数据正如预期的那样)
SYSTEM_INFO 结构看起来像这样,为简洁起见省略了 PROCESSOR_ARCHITECTURE 和 PROCESSOR_TYPE 枚举:
public struct SYSTEM_INFO
{
public PROCESSOR_ARCHITECTURE wProcessorArchitecture;
public ushort wReserved;
public uint dwPageSize;
public int lpMinimumApplicationAddress;
public int lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public PROCESSOR_TYPE dwProcessorType;
public uint dwAllocationGranularity;
public ushort wProcessorLevel;
public ushort wProcessorRevision;
}
对 GetSystemInfo 的外部调用是这样的:
[DllImport("kernel32")]
public static extern void GetSystemInfo(ref SYSTEM_INFO SystemInfo);
调用代码是这样的:
SYSTEM_INFO sysInfo = new SYSTEM_INFO();
GetSystemInfo(ref sysInfo);
运行代码后输出的 SYS_INFO 结构为:
dwActiveProcessorMask 4294901759
dwAllocationGranularity 0
dwNumberOfProcessors 2047
dwPageSize 4096
dwProcessorType 15
lpMaximumApplicationAddress 0
lpMinimumApplicationAddress 65536
wProcessorArchitecture 9
wProcessorLevel 4
wProcessorRevision 0
wReserved 0
关于我遗漏了什么的任何想法或关于获取此信息的其他方法的建议(我不想硬编码到 64Kb JIC 它在某些时候发生了变化)?谢谢。
最佳答案
你也没有 2047 处理器 :) 声明是错误的,它会在 64 位模式下失败。 lpMin/MaxApplicationAddress 和 dwActiveProcessorMask 是 IntPtr。
关于c# - 在 Win 7 上,GetSystemInfo 总是从 Windows 服务返回 0 分配粒度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7532507/