Detect whether the 3gb switch is on or off

I tried to determine if the 3GB switch is on or off in my program launched by calling GetSystemInfo () and checking lpMaximumApplicationAddress in the SYSTEM_INFO structure.

Bad luck. I think I'm doing something wrong.

How do you check if the 3GB switch is on in Windows to C? The code is evaluated.

thanks

+4
source share
3 answers

Assuming your program is compiled as a large address, you can simply call GlobalMemoryStatusEx and check the ullTotalVirtual field. If it exceeds 2 GB and you are working on a 32-bit system, the 3GB flag must be enabled.

Actually, I have no idea how to say whether Windows is originally 32 or 64 bits, but if you have a 32-bit process, you can call IsWow64Process to make sure that you are running on a 64-bit OS.

It all seems a bit indirect, I know :)

+3
source

Is your program IMAGE_FILE_LARGE_ADDRESS_AWARE?

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

Executable files that can use a 3 GB address space must have the IMAGE_FILE_LARGE_ADDRESS_AWARE bit set in the image header. If you are an executable file developer, you can specify the linker flag (/ LARGEADDRESSAWARE).

+3
source

FWIW, I was able to perform the discovery 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 ); } 

Code is executed in a process that is not LARGEADESSESSAWARE.

So far, I have been able to test Xp x86, Vista x86, and Seven x64.

+2
source

Source: https://habr.com/ru/post/1301745/


All Articles