GetSystemInfo总是返回0的dwAllocationGranularity在Win7从Win Service
本文关键字:Win7 Win Service dwAllocationGranularity 返回 GetSystemInfo | 更新日期: 2023-09-27 18:09:41
我试图从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.