visual-studio 如何使应用程序意识到大地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3109543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What to do to make application Large Address Aware?
提问by Suma
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 guideprovide a good starting point, but are by no means complete:
AMD 大型地址感知指南中列出的开发注意事项提供了一个很好的起点,但绝不是完整的:
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.
以下注意事项将有助于确保代码可以处理大于 2GB 的地址:
- 避免使用有符号指针算法(即比较和相加)
- 指针全部使用 32 位。不要将 Bit31 用于其他用途。
- 一些 dll 将在 2GB 边界下加载。在这种情况下,不能使用 VirtualAlloc() 分配连续的内存。
- 尽可能使用 GlobalMemoryStatusEx()(首选)或 GlobalMemoryStatus() 来检索内存大小。
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?
因此,问题是:在使 C++ Win32 本机应用程序大地址感知时需要完成的事情的完整列表是什么?
回答by Suma
- (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
- (显然)在项目属性中选择 Support Address Larger than 2 Gigabytes (/LARGEADDRESSAWARE):Linker / System / Enable Large Address
- 检查所有指针减法并验证结果存储在可以包含可能差异的类型中,或者用比较或其他构造替换它们 - 请参阅检测指针算术因为 LARGEADDRESSAWARE)。注意:指针比较应该没问题,与 AMD 建议相反,没有理由应该导致 4 GB 问题
- 确保您没有假设指针的 Bit31 为零,不要尝试将 Bit31 用于其他用途。
- 用 GetCursorInfo 替换所有 GetCursorPos 调用 - 请参阅GetCursorPos 因大地址而失败
- 对于 PVOID64 的所有分配,请使用 PtrToPtr64,例如在使用 ReadFileScatter 时需要,请参阅ReadFileScatter 备注部分

