How can I enable my 32-bit Delphi application to use 4gb of memory on 64-bit windows (via Wow64.exe)?

我只是一个虾纸丫 提交于 2019-11-28 09:59:49
gabr

See this CodeCentral article: Using more than 3 GB memory in a 32 bit Delphi program.

In modern Delphi versions just add compiler directive to the dpr: {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}

Use the linker directive $SetPEFlags:

{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}

The IMAGE_FILE_LARGE_ADDRESS_AWARE constant is defined in Windows.pas. I don't remember which Delphi version first included it, though.

In Delphi 2007, you'll find SetPEFlags documented in "PE (portable executable) header flags (Delphi)".

Some useful IMAGE_FILE_HEADER flags:

  • {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} //$0020

    Application can handle addresses larger than 2 GB.

  • {$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP} //$0800

    If the image is on the network, copy it to and run it from the swap file.

  • {$SetPEFlags IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP} //$0400

    If the image is on removable media, copy it to and run it from the swap file.

Some IMAGE_FILE_HEADER flags:

  • {$SetPEOptFlags IMAGE_DLLCHARACTERISTICS_NX_COMPAT} //$0100

    The image is compatible with data execution prevention (DEP).

  • {$SetPEOptFlags IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE} //$0040

    The DLL can be relocated at load time. (aka ASLR - Address Space Layout Randomization)

  • {$SetPEOptFlags IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE} //$8000

    The image is terminal server aware.

Note that there are assumptions baked into the compiler and RTL that pointers, interpreted as signed 32-bit integers, will never be negative. For example, the compiler will not permit creating a data structure greater than 2GB in size, and certain boundary checks in the RTL assume that e.g. Index + Count < 0 meant the addition overflowed, where Index may be an index into a byte array. Other problems may crop up in the memory manager.

Test well and proceed at your own risk.

If you do this, make sure to use FastMM because it supports > 2GB pointers. Earlier Delphi memory managers won't work well as Barry Kelly already described.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!