强制堆分配超过 4 GB [英] Force heap allocations above 4 GB

查看:19
本文介绍了强制堆分配超过 4 GB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同事将 32 位 C++ 应用程序转换为 64 位.出于测试目的,现在的想法是指示堆管理器仅返回 64 位范围内的地址.

在 Internet 上搜索解决方案似乎没有给出非常可靠的结果:

  • 如您所见,我修改了 SizeStartSizeEnd 以及 AddrStartAddrEnd.

    不幸的是,

    1. 这些文本框不接受 64 位地址
    2. 这些设置似乎没有效果

    虽然地址高于输入的值,但堆的大小没有改变:

    损坏时终止:已启用Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast(k) (k) (k) (k) 长度块续.堆-----------------------------------------------------------------------000001e0aa590000 00000002 2040 1528 2040 3 1 2 0 0000001e0aa440000 00001002 1080 248 1080 2 2 2 0 0000001e0aa410000 00008000 64 4 64 2 1 1 0 0000001e0aa520000 00001002 1080 104 1080 1 2 2 0 0000001e0af2f0000 00001002 60 60 60 6 1 1 0 0-----------------------------------------------------------------------

    这些应用程序验证程序设置是否仍然有效?如何成功应用它们?

    解决方案

    正如@HansPassant 在评论中提到的,Windows 8 分配超过 4 GB 的限制.这是因为 64 位应用程序是使用 /HIGHENTROPYVA 标记默认为 Raymond Chen 的旧的新东西"博文.

    对于 Windows 7,想法是使用 VirtualQuery(),检查MEM_FREE,然后用VirtualAlloc() 在这里你可以传递要分配的地址.>

    Colleagues convert a 32 bit C++ application to 64 Bit. For testing purposes, the idea is now to instruct the heap manager to return addresses in the 64 bit range only.

    Searching the Internet for solutions does not seem to give very reliable results:

    • MSDN forums suggest to use VirtualAlloc()before the CRT initializes. However, I can't see why that should not return a pointer to a high address already, leaving the bottom 4 GB empty.

    • Raymond Chen says, Windows 7 has a switch called Allocation­Preference which can be set to MEM_TOP_DOWN. However, that applies to the whole system and thus requires a reboot, which is inconvenient. (also described on MSDN).

    I dug around in application verifier and found some interesting options in the properties of the Heaps entry:

    As you can see I have modified SizeStart and SizeEnd as well as AddrStart and AddrEnd.

    Unfortunately,

    1. these text boxes do not accept 64 bit addresses
    2. these settings do not seem to have an effect

    While the addresses are above the entered values, the size of the heaps has not changed:

    Termination on corruption : ENABLED
              Heap     Flags   Reserv  Commit  Virt   Free  List   UCR  Virt  Lock  Fast 
                                (k)     (k)    (k)     (k) length      blocks cont. heap 
    -------------------------------------------------------------------------------------
    000001e0aa590000 00000002    2040   1528   2040      3     1     2    0      0      
    000001e0aa440000 00001002    1080    248   1080      2     2     2    0      0      
    000001e0aa410000 00008000      64      4     64      2     1     1    0      0      
    000001e0aa520000 00001002    1080    104   1080      1     2     2    0      0      
    000001e0af2f0000 00001002      60     60     60      6     1     1    0      0      
    -------------------------------------------------------------------------------------
    

    Do these application verifier settings still work? How to apply them successfully?

    解决方案

    As @HansPassant mentioned in the comments, Windows 8 allocates above the 4 GB limit. This is because 64 Bit applications are compiled with /HIGHENTROPYVA flag by default as mentioned in Raymond Chen's "The old new thing" blog post.

    For Windows 7, the idea is to use VirtualQuery(), check for MEM_FREE and then allocate all these regions with VirtualAlloc() where you can pass the address to be allocated.

    这篇关于强制堆分配超过 4 GB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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