5

I'm using the UPX compressor to compress my application written in Delphi XE. The file size goes from about 32 Mb to 8 Mb.

The strange thing I noticed, though, is that the occupation of the RAM increases significantly when running the compressed file. From 25/30 Mb goes to about 80 Mb. Is this normal or is it a problem you should keep? In my case, since the application runs on Windows Server 2008 remote desktop mode with multiple users, the system weighs disproportionately.

Why does this happen? How can I solve this problem?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Enzo Costantini
  • 167
  • 1
  • 9
  • 1
    How many users run the app at once? Each instance of the process consumes separate physical memory if you use a compressor. The pages cannot be shared. What is your motivation for using UPX? – David Heffernan Feb 09 '12 at 21:49
  • I don't know about UPX specifically, but at least some PE compressors decompress the entire image into memory at start-up. This is different from regular PEs where individual sections are paged in as needed. – 500 - Internal Server Error Feb 09 '12 at 21:57
  • Are you sure you don't have debug information linked in to the executable? That usually makes an even bigger difference for your filesize than compressing. One of my applications is 17MB with debug information, and less than 3 without it. – Wouter van Nifterick Feb 09 '12 at 22:42

1 Answers1

22

That's how EXE compressors work. They compress the disk file, not the executable code. To make the compressed file executable again, it needs to be uncompressed, and that uncompressed data is stored in memory. With an ordinary, non-compressed EXE file, the OS will load only the portions of the file that are required at the moment. The rest can stay on disk. Since your entire uncompressed application is in memory, that's why your memory usage appears higher.

Furthermore, the disk file can be shared by multiple users, whereas the memory containing the uncompressed executable is not shared. Each user running your program has a separate copy of the uncompressed program.

The 26 MB of disk space that you're saving by compressing your program are practically nothing on a shared remote-desktop server. Don't bother compressing the file. If you want to compress the file to save on bandwidth during distribution, then package your program in an installer that uncompresses the file once at installation time instead of an EXE compressor that needs to uncompress the file every time anyone runs it.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • 1
    +1 For the technical description on uncompressing into memory, and the advice NOT to compress a program. To Enzo: you should better **not use UPX** over Delphi executables. A lot of false positives warning may occur due to the AntiVirus - so [UPX is not worth it for Delphi Desktop applications](http://stackoverflow.com/questions/8937492/what-is-upxs-best-compression-method/8938525#8938525). – Arnaud Bouchez Feb 10 '12 at 06:28
  • Thank you, Rob Kennedy, you have been thorough! – Enzo Costantini Feb 10 '12 at 09:37