IMAGE_FILE_LARGE_ADDRESS_AWARE and 3GB OS Switch

2020-02-25 05:05发布

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.

标签: winapi memory
2条回答
不美不萌又怎样
2楼-- · 2020-02-25 05:38

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.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-02-25 05:50

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

查看更多
登录 后发表回答