17

I am currently in process of making our application Large Address Aware. As experience has shown, there are some unexpected gotchas when doing so. I create this post to make a complete list of steps which need to be taken.

The development considerations listed in the AMD Large Address Aware guide provide a good starting point, but are by no means complete:

The following considerations will help to make sure that the code can handle addresses larger than 2GB:

  • Avoid the use of signed pointer arithmetic (I.e. compares and adds)
  • Pointers use all 32-bits. Don’t use Bit31 for something else.
  • Some dll’s will be loaded just under the 2GB boundary. In this case, no consecutive memory can be allocated with VirtualAlloc().
  • Whenever possible, use GlobalMemoryStatusEx() (preferred) or GlobalMemoryStatus() to retrieve memory sizes.

Therefore, the question is: What is the complete list of things which need to be done when making C++ Win32 native application Large Address Aware?

Suma
  • 33,181
  • 16
  • 123
  • 191

1 Answers1

26
  • (obvious) select Support Address Larger than 2 Gigabytes (/LARGEADDRESSAWARE) in the project properties: Linker / System / Enable Large Address
  • check all pointer subtractions and verify the result is stored in a type which can contain the possible difference, or replace them with comparisons or other constructs - see Detect pointer arithmetics because of LARGEADDRESSAWARE). Note: pointer comparison should be fine, contrary to AMD advice, there is no reason why it should cause 4 GB issues
  • make sure you are not assuming pointers have Bit31 zero, do not attempt to use Bit31 for something else.
  • replace all GetCursorPos calls with GetCursorInfo - see GetCursorPos fails with large addresses
  • for all assignments into PVOID64 use PtrToPtr64, needed e.g. when using ReadFileScatter, see ReadFileScatter remark section
Community
  • 1
  • 1
Suma
  • 33,181
  • 16
  • 123
  • 191
  • "Eliminate all pointer substractions" is excessive. Pointers within an single array work perfectly fine. – MSalters Jun 25 '10 at 09:27
  • @Suma: pointer additions are NOT fine, since pointer additions can overflow when `LARGEADDRESSAWARE` is set. – Mooing Duck May 20 '13 at 21:14
  • in addition: watch out for 3rd party libraries discussed here: http://stackoverflow.com/questions/2288728/ – Opmet Apr 09 '14 at 11:17
  • Need this linker option, /LARGEADDRESSAWARE only be set once, for linking the application EXE, or must it also be set for linking component DLLs as well? – David M. Miller Feb 02 '15 at 13:54
  • @DavidM.Miller It seems the flag has no effect on DLL - http://stackoverflow.com/questions/2927598/linking-to-a-large-address-aware-dll . Just make sure the DLLs you use with the exe really can handle the large addresses. – Suma Feb 02 '15 at 18:08