我可以做些什么来减少可执行文件的大小(Delphi)? [英] What Can I Do To Reduce My Executable's Size (Delphi)?

查看:237
本文介绍了我可以做些什么来减少可执行文件的大小(Delphi)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布了一个使用Delphi 2009的桌面程序的单一可执行文件(.EXE)。我没有外部DLL或资源,我需要该程序运行。



我使用两个组件: LMD Innovative的ELPack Sergey Tkachenko的TRichView 被编译成我的可执行文件。



当我构建我的生产版本,使用释放构建配置,生成的可执行文件为13,533 KB。



在使用Delphi 2009之前,我使用的是Delphi 4.它生成的可执行文件只有2,671 KB,同时包含相同的两个组件,并且基本上具有与我当前相同的代码



我明白Delphi 2009完全是Unicode(这是我升级的主要原因),而Unicode可能会增加一倍的大小。但是这是大约5倍的大小。



有没有为什么我的可执行文件要保持5倍的原因?还是有一些简单的方式来减少可执行大小的一大部分?






请注意。有些人正在回答压缩德尔福EXE的方法。这不是我想要做的。我想简单地看看为什么要用太多的空间去除可能没有必要的空间。如果这样做,如果需要,压缩仍然可以进行。



一旦安装了可执行文件,实际上并不重要。它用于下载目的,并尽可能减少要压缩的服务器负载和下载时间。我更喜欢使用 Inno Setup 并压缩安装程序本身内的程序。然后,当它被安装时,它被扩展到全尺寸。这两个都可以防止作为病毒的可能检测,并消除在内存中解压缩程序所需的额外启动时间。另外我的代码是我的可执行文件和我的安装例程,一些压缩技术与此不兼容。



有关压缩的更多信息,请参阅StackOverflow问题:德尔福EXE压缩机?






ldsandon要我提供我正在使用的选项,所以这里是:



编译选项http://www.beholdgenealogy.com/img/compilingoptions.jpg



链接选项http://www.beholdgenealogy.com/img/linkingoptions.jpg

解决方案

当从Delphi 7移植到Delphi 2010时,我们的.exe的增长例如从16兆字节增加到35兆。



几周前,我在Embarcadero论坛上提出了类似于您的问题。 (链接)在我的OP中,我列出了一系列链接主题,你可能会发现有用的。



我们尝试使用UPX压缩我们的.exe文件。让它工作几个小时大大减少了我们的.exe,但是我们可能不会在生产中使用它们,原因如下:


  1. 我们有相当多的.exe的,不想等待每一个构建的1/2天。 (有可能我们可以找到一个非强制的参数集,可以减少这个...)


  2. 尽管.exe的大小被减少,我们的可运输不是,因为我们的安装程序(不出意料之外)不能从压缩的压缩文件中压缩更多的压缩文件,而是能够将原来的16兆的exe文件减少我已经阅读了一些报告,在某些时候(很少,但不是永远不会),UPX exe引发了各种反病毒程序来报告该应用程序包含病毒。 (我不记得我看到这个的日期,地点或细节,所以我在这里报告有点不公平)。但是,我们非常不利于承担甚至可能发生的风险,即UPX是在桌子上...


Embarcadero论坛上的链接还包括一个链接到另一个SO主题。



我继续感到惊讶和失望的是我们发现Delphi 2010时发现的代码膨胀。正如Nick所说,Unicode的2X相当过分。但是,由于IMO,D2010在许多其他方面都是如此惊人的升级,所以在转向D2010时,这种膨胀是一个较小的折中。但是, 意味着我们可能需要转移到2张CD而不是1张CD。我不期待看到我们组织对此的反应...


I release a single executable (.EXE) for a desktop program using Delphi 2009. I have no external DLLs or resources that I need for the program to run.

I use two components: LMD Innovative's ELPack and Sergey Tkachenko's TRichView that are compiled into my executable.

When I build my production version, using the "Release" build configuration, the executable file produced is 13,533 KB.

Prior to using Delphi 2009, I was using Delphi 4. The executable it produced was only 2,671 KB while incorporating the same two components and basically having the same code as my current version.

I do understand that Delphi 2009 is completely Unicode (which is the main reason why I upgraded), and being Unicode can cause up to a doubling of size. But this is about 5 times larger.

Is there a reason why my executable has to remain 5 times larger? Or are there some simple ways to cut down a significant chunk of the executable size?


Please note. Some people are answering with ways to compress the Delphi EXE. That is not what I am trying to do. I am trying to simply see why so much space is being used to remove what might not be necessary. If that is done, compression can still be done afterwards if so desired.

It really doesn't matter how big or small the executable is once it is installed. It is for downloading purposes and to minimize server load and download times that you want to compress it. I prefer to use Inno Setup and compress the program inside the install routine itself. Then when it is installed, it is expanded to full size. That both prevents possible detection as a virus and eliminates the extra startup time needed to uncompress the program in memory. Also I code sign both my executable and my install routine and some compression techniques are incompatible with that.

For more info about compressing, see the StackOverflow question: Delphi EXE compressor?


ldsandon asked me to provide exactly what options I'm using, so here they are:

Compiling Options http://www.beholdgenealogy.com/img/compilingoptions.jpg

Linking Options http://www.beholdgenealogy.com/img/linkingoptions.jpg

解决方案

When moving from Delphi 7 to Delphi 2010., our .exe's grew for example from 16 megs to 35 megs.

I asked a question similar to yours on the Embarcadero forum a few weeks ago. (link) In my OP, I listed a series of links on this subject that you might find helpful.

We tried using UPX to compress our .exe's. Letting it work for hours significantly reduced our .exe, but we probably won't use it in production for these reasons:

  1. We have quite a few .exe's and don't want to wait 1/2-day on each build. (It's possible that we could find a non-brute force set of parameters to UPX that would reduce this...)

  2. Although the size of the .exe is reduced, our shippable was not, because our installer (not surprisingly) is unable squeeze much more compression out of the already compressed file... whereas it was able to reduce the original 16 meg .exe down to 8 megs.

  3. I've read some reports that at some time (rarely, but not never), UPX exe's triggered various anti-virus programs to report the application contained a virus. (I don't recall the date, site, or details of where I saw this, so it's a bit unfair of me to report it here.) But, we are so adverse to taking a risk of that even possibility happening, that UPX is off the table...

The link on the Embarcadero forum also includes a link to another SO thread on this topic.

I continue to be surprised and disappointed at the code bloat we found when moving to Delphi 2010. As Nick notes, 2X for Unicode is quite excessive.

However, the bloat is a relatively minor trade-off when moving to D2010, because, IMO, D2010 is such a terrific upgrade in so many other ways. But, it does mean that we'll probably have to move to shipping 2 CDs rather than one. I'm not looking forward to seeing the reaction to this from our organization...

这篇关于我可以做些什么来减少可执行文件的大小(Delphi)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆