如何实现较小尺寸的可执行文件? [英] How to achieve smaller size of the executable?

查看:172
本文介绍了如何实现较小尺寸的可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我在长时间的停顿后回到了Delphi,写了一个非常直接的实用程序,我的客户端要求支持旧版本。



我知道这几天的大小并不重要,但是令我感到奇怪的是,一个单位的应用程序在编译时总共为1'084'416 b的可执行文件。我写的唯一的.pas单位是大约20.8k大,主要是因为gui的丰富程度。



使用子句如下:

 使用
Windows,Messages,SysUtils,Variants,Classes,Controls,窗体,strutils,
对话框,ADODB,DB,DBGrids,ExtCtrls,DBCtrls,StdCtrls,网格,菜单,
按钮;

我想知道有没有办法将应用程序的大小减少到300-400k或更少?

解决方案


  1. 您是否进行了调试或发布构建? (将其发布为较小的尺寸,确保优化已启用,关闭调试信息)


  2. 是否关闭了RTII(delphi 2010及更高版本)需要? (较小的EXE大小)


  3. 您的主单元的用法子句中的单位数不是猜测EXE大小的好方法。以这种方式思考:VCL本身是一大堆代码,另一个是数据库层,你写的东西可能是EXE大小的一小部分。


  4. 要了解您的可执行文件大小,请尝试使用JCL项目分析器,或者阅读打开地图选项时生成的MAP文件。这将告诉你可执行文件的内容。


由于各种原因,这将是愚蠢的,但你可以例如通过使用Delphi 7获得一个较小的可执行文件。最后,当我做一个应用程序,我想让它更小,我看看需要多少时间,重建一切(如vcl替代)多少努力,然后我对自己说,忘记了它。


Very recently I have come back to Delphi after a long pause and written a rather straightforward utility app my client requested to support an older release...

I know these days the size does not matter much, but it struck me as odd that the one-unit application, when compiled, amounted to 1'084'416 b executable. The one and only .pas unit I wrote is some 20.8k large, mostly because of the richness of the gui.

The uses clause is as follows:

uses
  Windows, Messages, SysUtils, Variants, Classes, Controls, Forms, strutils,
  Dialogs, ADODB, DB, DBGrids, ExtCtrls, DBCtrls, StdCtrls, Grids, Menus,
  Buttons;

I wonder if there's any way I could reduce the size of the application to 300-400k or less?

解决方案

  1. Did you do a debug or release build? (Make it release for smaller size, make sure optimization is on, debug information turned off)

  2. Did you turn off RTII (delphi 2010 and up) if not needed? (Smaller EXE sizes.)

  3. Number of units in your uses clause of your main unit, is not a good way to guess EXE size. Think of it this way: The VCL itself is one large amount of code, the Database Layer another, and the stuff you write is probably a very small percentage of the EXE size.

  4. To understand your executable size, try the JCL Project Analyzer, or read the MAP file that is produced when you turn on the Map option. This will tell you exactly what is inside your executable file.

It would be silly for various reasons, but you could get a smaller executable by using Delphi 7, for example. In the end when I make an application and I want to make it smaller, I look at how much time it would take, and how much effort to rebuild everything (such as with a vcl alternative) and I then say to myself, forget about it.

这篇关于如何实现较小尺寸的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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