开发者

Detect whether the 3gb Switch is on or off programmatically

I've been trying to determine whether the 3GB switch is on or off on the system my program is running by calling GetSystemInfo() and checking lpMaximumApplicationAddress on the SYSTEM_INFO struct.

No luck. I think I am doing something wrong.

How do you check whether the 3GB switch is on or开发者_运维问答 not on Windows in C? Code is appreciated.

thanks


Assuming your program is compiled as large address aware, you could simply call GlobalMemoryStatusEx and check the ullTotalVirtual field. If it's larger than 2GB, and you're running on a 32-bit system, then the 3GB flag must be turned on.

I actually have no idea how to 'properly' tell if Windows is natively 32 or 64 bit, but if you have a 32-bit process you could call IsWow64Process to see if you're running on a 64-bit OS.

This all seems a bit indirect, I know :)


Is your program IMAGE_FILE_LARGE_ADDRESS_AWARE ?

http://www.microsoft.com/whdc/system/platform/server/PAE/PAEmem.mspx

Executables that can use the 3-GB address space are required to have the bit IMAGE_FILE_LARGE_ADDRESS_AWARE set in their image header. If you are the developer of the executable, you can specify a linker flag (/LARGEADDRESSAWARE).


FWIW, I've been able to do the detection using the following code (found here) :

if (!isWow64())
{
  BOOL b3GBSwitch = FALSE;
  SYSTEM_INFO siSysInfo;
  GetSystemInfo(&siSysInfo);
  b3GBSwitch = ((DWORD)siSysInfo.lpMaximumApplicationAddress & 0x80000000) != 0;
  printf("3GB Switch Enabled: %d\n", b3GBSwitch );
}

The code is executed in a process that is not LARGEADDRESSAWARE.

So far I've been able to test on Xp x86, Vista x86 and Seven x64.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜