如何在 x64 C++ 应用程序中保留底部 4GB 虚拟机 [英] How to reserve bottom 4GB VM in an x64 C++ app

查看:17
本文介绍了如何在 x64 C++ 应用程序中保留底部 4GB 虚拟机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

致力于将 32 位 Windows C++ 应用程序移植到 64 位.不幸的是,该代码在 DWORD 和指针值之间使用了双向频繁转换.

Working on porting a 32bit Windows C++ app to 64 bit. Unfortunately, the code uses frequent casting in both directions between DWORD and pointer values.

其中一个想法是在进程启动时尽早保留前4GB的虚拟进程空间,以便后续所有保留内存的调用都来自大于4GB的虚拟地址.这将导致访问冲突错误,任何从指针到 DWORD 然后返回到指针的不安全强制转换都将有助于及早捕获错误.

One of the ideas is to reserve the first 4GB of virtual process space as early as possible during process startup so that all subsequent calls to reserve memory will be from virtual addresses greater than 4 GB. This would cause an access violation error any unsafe cast from pointer to DWORD and then back to pointer and would help catch errors early.

当我查看一个非常简单的单行 C++ 程序的内存映射时,底部 4GB 内加载了许多库?有没有办法确保所有库等只加载到 4GB 以上?

When I look at the memory map of a very simple one line C++ program, there are many libraries loaded within bottom 4GB? Is there a way to make sure that all libraries, etc get loaded only above 4GB?

谢谢

推荐答案

使用 /Wp64 开关编译您的项目(检测 64 位可移植性问题)并修复所有警告.

Compile your project with /Wp64 switch (Detect 64-bit Portability Issues) and fix all warnings.

这篇关于如何在 x64 C++ 应用程序中保留底部 4GB 虚拟机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆