tags:

views:

196

answers:

2

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

+3  A: 

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).

John Knoeller
I just need to know whether it's on or not. that's all
Jessica
The program you use to test whether it's on must be built /LARGEADDRESSAWARE. is it?
John Knoeller
thanks.I'll ask again: Is there a way to know whether the 3gb switch is ON or OFF by code? If yes, do you know how to do this? regardless of whether that flag is set.
Jessica
@Jessica: I think John is trying to tell you that Windows will lie to your application unless the `IMAGE_FILE_LARGE_ADDRESS_AWARE` bit is set in the executable.
Michael Burr
+1  A: 

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 :)

David M