views:

414

answers:

4

According to this MSDN page:

WOW64 enables 32-bit applications to take advantage of the 64-bit kernel. Therefore, 32-bit applications can use a larger number of kernel handles and window handles. However, 32-bit applications may not be able to create as many threads under WOW64 as they can when running natively on x86-based systems because WOW64 allocates an additional 64-bit stack (usually 512 KB) for each thread. In addition, some amount of address space is reserved for WOW64 itself and the data structures it uses. The amount reserved depends on the processor; more is reserved on the Intel Itanium than on the x64 processor.

If the application has the IMAGE_FILE_LARGE_ADDRESS_AWARE flag set in the image header, each 32-bit application receives 4 GB of virtual address space in the WOW64 environment. If the IMAGE_FILE_LARGE_ADDRESS_AWARE flag is not set, each 32-bit application receives 2 GB of virtual address space in the WOW64 environment.

How do I effectively set the IMAGE_FILE_LARGE_ADDRESS_AWARE flag in my Delphi 2007 application so that I can make my 32-bit application Wow64 aware and address up to a full 4GB of memory?

+8  A: 

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

gabr
+5  A: 

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)", or in the link ms-help://borland.bds5/devcommon/peheaderflags_xml.html

Ken White
+5  A: 

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.

Barry Kelly
Any chance for such issues in RTL/VCL to be fixed, if any exist? :)
Alexander
Why should pointers ever be interpreted as signed 32-bit integers? That sounds like a flawed design to me that Embarcadero should fix, particularly as you don't seem to be in a hurry to release a 64-bit version of Delphi.
Jan Goyvaerts
@Jan Goyvaerts - to simply, easily and efficiently detect overflow, like I described. And the marketing and product decisions around 64-bit etc. are completely irrelevant to the specific technical warning I'm issuing here.
Barry Kelly
+1  A: 

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.

Frederik Slijkerman