I'm attempting to get the allocation granularity size using GetSystemInfo() from a C# 3.5 windows service application on Windows 7. However the SYSTEM_INFO struct always has 0 in dwAllocationGranularity when it is returned from the call (other fields have data filled in as expected)
The SYSTEM_INFO struct looks like this with PROCESSOR_ARCHITECTURE and PROCESSOR_TYPE enums omitted for brevity:
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;
}
The extern call to GetSystemInfo is this:
[DllImport("kernel32")]
public static extern void GetSystemInfo(ref SYSTEM_INFO SystemInfo);
The calling code is like this:
SYSTEM_INFO sysInfo = new SYSTEM_INFO();
GetSystemInfo(ref sysInfo);
The Output SYS_INFO struct after running code is:
dwActiveProcessorMask 4294901759
dwAllocationGranularity 0
dwNumberOfProcessors 2047
dwPageSize 4096
dwProcessorType 15
lpMaximumApplicationAddress 0
lpMinimumApplicationAddress 65536
wProcessorArchitecture 9
wProcessorLevel 4
wProcessorRevision 0
wReserved 0
Any ideas what I'm missing or suggestions on other ways to get this info (I don't want to hard code to 64Kb JIC it i开发者_开发百科s changed at some point)? Thanks.
You also don't have 2047 processors :) The declaration is wrong, it will fail in 64-bit mode. lpMin/MaxApplicationAddress and dwActiveProcessorMask are IntPtr.
精彩评论