[英]GetSystemInfo always returns 0 for dwAllocationGranularity on Win7 from Win Service
我正在尝试从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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.