我该怎么做才能减小可执行文件的大小 (Delphi)? [英] What Can I Do To Reduce My Executable's Size (Delphi)?

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

问题描述

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

我使用两个组件:
(来源:
(来源:beholdgenealogy.com)

解决方案

当从 Delphi 7 迁移到 Delphi 2010 时,我们的 .exe 文件从 16 兆增加到 35 兆.

几周前,我在 Embarcadero 论坛上提出了一个与您类似的问题.(link)在我的 OP 中,我列出了一系列链接这个主题,你可能会觉得有帮助.

我们尝试使用 UPX 来压缩我们的 .exe.让它运行几个小时大大减少了我们的 .exe,但由于以下原因,我们可能不会在生产中使用它:

  1. 我们有很多 .exe,不想在每次构建时等待 1/2 天.(我们有可能找到一组非暴力的 UPX 参数来减少这种情况......)

  2. 虽然 .exe 的大小减小了,但我们的可交付没有减小,因为我们的安装程序(毫不奇怪)无法从已经压缩的文件中挤出更多的压缩...而它能够将原来的 16 兆 .exe 减少到 8 兆.

  3. 我读过一些报告,说在某些时候(很少,但并非从来没有),UPX exe 会触发各种防病毒程序报告该应用程序包含病毒.(我不记得我看到这个的日期、地点或细节,所以我在这里报告它有点不公平.)但是,我们非常不愿意冒这种甚至可能发生的风险,UPX不在桌子上...

Embarcadero 论坛上的链接还包括一个链接 到另一个关于此主题的 SO 线程.

我们在迁移到 Delphi 2010 时发现的代码膨胀让我继续感到惊讶和失望.正如 Nick 指出的那样,Unicode 的 2X 是相当多的.

然而,在迁移到 D2010 时,膨胀是一个相对较小的权衡,因为,IMO,D2010 在许多其他方面都是如此出色的升级.但是,这确实意味着我们可能不得不转而运送 2 张 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:


(source: beholdgenealogy.com)


(source: beholdgenealogy.com)

解决方案

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天全站免登陆