为什么在 64 位 Windows 中运行时有 2 GB 内存限制?
我是开发 Delphi 应用程序的团队的成员。内存需求巨大。 500 MB 是正常的,但在某些情况下会出现内存不足的异常。在这种情况下分配的内存通常在 1000 - 1700 MB 之间。
我们当然想要 64 位编译器,但这现在不会发生(如果发生,我们也必须转换为 unicode,但那是另一个故事了......)。
我的问题是为什么在 64 位环境中运行时每个进程有 2 GB 内存限制。指针是 32 位的,所以我认为 4 GB 是正确的限制。 我使用 Delphi 2007。
编辑: 因此,如果我在 Delphi 中设置 IMAGE_FILE_LARGE_ADDRESS_AWARE 标志,方法是:
{$SetPeFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
在 Windows Server 2003 x64 上运行生成的 Exe 文件,那么应用程序可以寻址 4 GB 吗?
- 我应该在 boot.ini 中设置 /3GB 开关吗?
- 我们已经尝试过此操作,但在 32 位 Windows Server 2003 上,它似乎限制了 Windows 资源。日志中存在更多“内存不足”和 GDIError 异常。但在 64 位操作系统中运行时,这种情况可能会消失吗?
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 allocated in that cases is typically between 1000 - 1700 MB.
We of course want 64-bits compiler but that won't happen now (and if it happens we also must convert to unicode, but that is another story...).
My question is why is there a 2 GB memory limit per process when running in a 64 bit environment. The pointer is 32 bit so I think 4 GB would be the right limit.
I use Delphi 2007.
EDIT:
So if I set the IMAGE_FILE_LARGE_ADDRESS_AWARE flag in Delphi by using:
{$SetPeFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
And running the resulting Exe-file on a Windows Server 2003 x64 then the application can address 4 GB ?
- Should I set /3GB switch in boot.ini ?
- We have tried this but on a 32 bit Windows Server 2003 and it seems to limit the windows resources. There was more exceptions for "Out of memory" with GDIError in the log. But maybe this disappear when running in a 64 bit OS ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用 /LARGEADDRESSAWARE 标志编译 Delphi 应用程序,它将能够在 64 位操作系统上寻址完整的 4GB。否则,当在 WOW32 中运行时,操作系统假定应用程序期望与在 32 位操作系统上具有相同的环境,这意味着在 4GB 地址空间中,2GB 专用于操作系统,2GB 分配给该应用程序。
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.
Delphi 中在 PE 可执行文件中设置 LARGEADDRESSAWARE 标志的语法是:
将其放入 .dpr 文件中。
The syntax in Delphi to set the LARGEADDRESSAWARE flag in the PE executable is:
Put that in your .dpr file.
http://msdn.microsoft.com/en-us /library/aa366778(VS.85).aspx
每个 32 位进程的用户模式虚拟地址空间:2 GB
http://msdn.microsoft.com/en-us/library/aa366778(VS.85).aspx
User-mode virtual address space for each 32-bit process: 2 GB
只要您选择接收设置了高位的 32 位指针(通过包含
LARGE_ADDRESS_AWARE
PE 标志),就没有 2GB 限制。直接观察
结论
在 64 位 Windows 上没有 2GB 限制,只要你发誓就可以处理高于 $7FFFFFFF 的指针。
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
Conclusion
There is no 2GB limit, on 64-bit Windows, as long as you swear you can handle pointers above $7FFFFFFF.