views:

1060

answers:

3

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 ?
+6  A: 

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

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

mgroves
There is no way for Windows to know if Delphi uses signed or unsigned arithmetic on memory addresses, so it must assume the upper bit is unusable unless you explicitly declare otherwise.
Mark Ransom
@Mark: That's, uh, not true at all. As stated above, setting a bootup flag will allow Delphi to address more than 2GB
BlueRaja - Danny Pflughoeft
@BlueRaja, "setting a bootup flag" = "explicitly declare otherwise".
Mark Ransom
@Mark: I mean a bootup flag in the OS. It has nothing to do at all with Delphi, or signed arithmetic (pointer arithmetic is the same whether signed or unsigned!)
BlueRaja - Danny Pflughoeft
@BlueRaja: you're wrong. http://blogs.msdn.com/oldnewthing/archive/2004/08/12/213468.aspx
Alexander
+23  A: 

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.

Thomas
That's only valid on 32bit. There's no binary difference between a 3GB pointer and a 4GB pointer, so any app that can handle 3GB can do 4GB. /LARGEADDRESSAWARE is good for the full 4GB on 64bit systems without any boot up modifications. The only time you have to do /3GB is if you want to use more address space in a 32bit system. The article you linked is about ten years out of date, and only addresses 32bit systems.PAE is an entirely different system.
DeadMG
@Dead: Yes, of course on 64-bit systems (http://support.microsoft.com/kb/294418) tho the original article is only 5 years out of date, not 10. :) The answer however remains wrong/incomplete in respect to it's discussion of implications on 32-bit OS's.
Deltics
@Deltics - LARGEADDRESSAWARE does not only apply to 3GB That is absolutely incorrect. http://msdn.microsoft.com/en-us/library/wz223b1z%28VS.80%29.aspx. It is an indication that the application can handle **ANY** addresses above 2GB. It is absolutely correct that if you want the full 4GB of address space on a 64-bit OS with a 32-bit application and if it can handle it, you can use the LARGEADDRESSAWARE switch. I'm not sure why you think this is incorrect.
Thomas
The answer specifically syas 64-bit OS, so what's the problem?
Mark Ransom
@Deltics - Further, the first paragraph in the article you provide completely supports what I was saying about 4GB address space and the use of 2GB for the OS and 2GB for the application. That is the default behavior on a 32-bit OS. The /3GB is a *feature* which you can *manually* enable that changes this dynamic so that up to 3GB can be allocated to an application **if** it is designed to handle the additional addressing.
Thomas
You can use {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} instead of a compiler switch to get the same behavior. This isn't without its caveats though. Barry Kelly mentioned there may be problems with using it: http://stackoverflow.com/questions/1849344/how-can-i-enable-my-32-bit-delphi-application-to-use-4gb-of-memory-on-64-bit-wind
Craig Peterson
@ All: Yes, no problem other than a second sentence starting with a conjunction that managed to confuse me. My bad. I have removed the offending comment not to save my blushes as much as to avoid planting the seeds of doubt in anyone's mind.
Deltics
+9  A: 

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.

ldsandon