views:

69

answers:

1

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?

+4  A: 
  • (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 But31 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
Suma
+1 very good answer
PeterK
"Eliminate all pointer substractions" is excessive. Pointers within an single array work perfectly fine.
MSalters