tags:

views:

3847

answers:

2

If a Windows application has the IMAGE_FILE_LARGE_ADDRESS_AWARE set in the image header (via the /LARGEADDRESSAWARE compiler flag), this is typically to allow a 32-bit application to use more than 2GB of memory (only makes sense if the 32-bit Operating System has set the 3GB switch in boot.ini). See MSDN article /3GB for more info.

My questions is, what happens if you run this application on a system that does NOT have the 3GB switch set. Is it simply ignored? Or will the app try and use a 3GB heap and get out-of-memory errors because the userspace only has 2GB available?

I keep hearing anecdotally that the LARGEADDRESSAWARE switch is ignored for 2GB userspace systems but cannot find any official Microsoft documentation on this.

Thanks in advance.

+5  A: 

The switch is ignored, if you can call it that. For once, Microsoft actually managed to come up with a descriptive name.

The flag means exactly what it says. This image file is aware that large addresses exist. That is, it won't crash, if it is given a pointer above the 2GB boundary.

And that's all. The OS doesn't have to treat the process special in any way. It simply indicates that if the OS is able to provide more than 2GB memory, this process can handle it without crashing. You can make a simple hello world application which never uses more than 1.5MB, and still has this flag set. It doesn't mean "I want to use 3GB of memory", it means "When I request memory, I don't care if it's above or below the 2GB boundary".

So since the flag doesn't require the OS to do anything special, the OS simply won't do anything special if there is nothing special it can do.

jalf
+6  A: 

Basically the IMAGE_FILE_LARGE_ADDRESS_AWARE tells the system, "I know that addresses with the high bit set are not negative, and can handle them". If the system is prepared to provide user mode addresses above 2GB, then it will. If the system is not prepared to give those addresses (ie., a 32-bit Windows OS without the /3GB setting), the process can't get those addresses anyway - but no harm done.

Also note that if an image has the IMAGE_FILE_LARGE_ADDRESS_AWARE bit set it will get access to address space above 2GB on Win64 systems, which do not support (or need) the /3GB switch. A 32-bit application will get an address space of something close to 4GB and a 64-bit application will get a huge address space - 7TB to 8TB depending on the platform (64-bit builds set the bit by default).

http://msdn.microsoft.com/en-us/library/aa366778.aspx#memory_limits

Michael Burr
Note:On a 32bit system use 3Gb at your own risk - if you don't control the hardware and drivers you can end up with a high chance of blue screening. On Win64 - it gives you completely safe 4Gb addresss for a 32 bit process. Also note you can tweak a binary to set the flag.
morechilli
<i>if you don't control the hardware and drivers you can end up with a high chance of blue screening</i>I'm assuming this is because the kernelspace goes down to 1 GB, so if you have lots of drivers its possible to run out of memory.
Todd
Todd: Yeah, but it's not just that. A lot of drivers may simply make the assumption that "all pointers to addresses >2GB point to kernel space, everything <2GB is userspace.
jalf