Why 2 GB memory limit when running in 64 bit Windows?

前端 未结 4 1337
小蘑菇
小蘑菇 2020-12-13 14:23

I\'m a member in a team that develop a Delphi application. The memory requirements are huge. 500 MB is normal but in some cases it got out of memory exception. The memory al

相关标签:
4条回答
  • 2020-12-13 14:26

    If you compile the Delphi application using the /LARGEADDRESSAWARE flag, it will be able to address the full 4GB on a 64-bit OS. Otherwise, when running in a WOW32, the OS assumes that the app is expecting the same environment that it would have on a 32-bit OS which means that of the 4GB of address space, 2GB is dedicated for the OS and 2GB is allocated to the application.

    0 讨论(0)
  • 2020-12-13 14:34

    http://msdn.microsoft.com/en-us/library/aa366778(VS.85).aspx

    User-mode virtual address space for each 32-bit process: 2 GB

    0 讨论(0)
  • 2020-12-13 14:44

    The syntax in Delphi to set the LARGEADDRESSAWARE flag in the PE executable is:

    {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
    

    Put that in your .dpr file.

    0 讨论(0)
  • 2020-12-13 14:46

    As long as you opt into receiving 32-bit pointers with the high-bit set (by including the LARGE_ADDRESS_AWARE PE flag), there is no 2GB limit.

    Direct Observation

    var
       p: Pointer;
       n: Int64;
    begin
       p := Pointer($D0000000); //Above the 2GB line; and the 3GB line!
    
       p := VirtualAlloc(p, 1024, MEM_COMMIT or MEM_RESERVE, PAGE_READWRITE);
       if p = nil then
          RaiseLastWin32Error;
    
       n := Cardinal(p);
       ShowMessage(IntToHex(n, 16));
    end;
    

    enter image description here

    Conclusion

    There is no 2GB limit, on 64-bit Windows, as long as you swear you can handle pointers above $7FFFFFFF.

    Note: Any code is released into the public domain. No attribution required.

    0 讨论(0)
提交回复
热议问题