4

I really lack experience on developing things on Windows, and I may have missed some obvious things, try to stay calm :)

I have an application (Qt C++) which uses some .dlls from its own path (I mean I deliver those .dlls along with the .exe). When I deliver the app, I compress the dlls via upx. It dramatically compresses them and I can use those dlls without decompressing.

I have the impression that I am doing something wrong but it just works by chance, so I wanted to be sure, is it ok to use a compressed dll? Or should I expect unpredictable problems at anytime? (This is being the main question)

If .dlls can be used in compressed mode so why the earth do we have them uncompressed in the first place.

destan
  • 4,301
  • 3
  • 35
  • 62
  • Windows does not support compressed DLLs by itself. If you have a problem, you'll have to check with UPX makers. Why would you want to compress your dlls in the first place? Is your program so huge? (PS: Windows can be configured to compress directories). – Simon Mourier Jan 23 '13 at 13:03
  • actually my program is tiny yet the dlls it depends are big so users wouldn't want to download 50mb for a tiny util... – destan Jan 23 '13 at 16:43

1 Answers1

9

This is not something that "works by chance", UPX is intended to compress Win32-PE (and many other formats), whether that's executables or DLLs.

As for "Is it OK?", well yes, of course it is "OK", as long as you don't violate another party's license. This is highly unlikely to happen with anything related to Qt, but in principle, it is a possibility. One could for example be using some DLLs which have a license clause such as "distribution in binary form, blah blah, not allowed to modify". Say, something like a MSVC or DirectX redistributable, or some graphic card vendor's proprietary API. In any case, it's not a mistake to keep this in mind and check the licenses before risking to violate them.

Wording your question "Is it OK?" slightly different: "Is it wise?", the answer is: probably not. A few megabytes extra on the disk normally don't matter a lot. When you pack everything into an installer, and a user downloads it over the internet, the data is compressed anyway, so it's the same in that respect.

However, compression, whether you use UPX or another executable packer, or Windows' filesystem compression, has side effects. It causes additional address space fragmentation, it disables asynchronous transfers, and it forfeits the operating system's ability to discard pages from the DLL from the working set and to transparently reload them from the PE image upon access.

That last sentence means the operating system must make an allocation in the page file and it must write pages to the page file when your process' working set is moved out to make room for something else. There is no other way. Now what if the user has disabled page files...

Damon
  • 67,688
  • 20
  • 135
  • 185