Solved

Application size

Posted on 2000-04-23
27
165 Views
Last Modified: 2010-04-04
Why are my Delphi applications always so big, and what can I do to reduce their size??
0
Comment
Question by:nrico
  • 9
  • 6
  • 3
  • +5
27 Comments
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
there are a few things you could do:

1. Turn off "Compile with Debug info".
   This will cut down the size considerably.

2. Consider compiling resources into
   companion libraries. If you have a lot of bitmaps or icons in your project, use a resource DLL. This way the EXE is that much smaller, plus it could possibly run faster, since you need only load that DLL when it is needed.

3. Check for repitive code and compartmentalize it. If you have a routine that does something that another routine is doing (for example buttonclick events), you could make a single routine which takes parameters.

For example:
OLD WAY:
Procedure Button1Click(sender:Tobject)
begin
  Showmessage(Button1.name)
end;

Procedure Button2lick(sender:Tobject)
begin
  Showmessage(Button2.name)
end;

NEW WAY:
Procedure NewButtonClick(Sender:Tobject)
begin
  ShowMessage((Sender as TButton).Name)  

* this is a simplistic example, but you get the point.



Good luck!!

0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
how big ?

you can exclude the debuginfo (if not done) at
Project|Options|Linker|EXE and DLL Options
turn all off (integrated debugging works also)

this will make the exe ~75% smaller
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
Does it? I tried turning of debug information but it didn't give me any size gain.
And I'm talking about 300+ Kb for a program that does, well, nothing yet.
0
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
if you have any forms whatsoever, you are not going to get an application for less than that. The forms unit adds a miniumn of ~200k, linking adds the rest.
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
DrDelphi --
  Yes, of course I know those optizations. But my CGI app doesn't contain resources or much procedures, and I want it as small as possible.
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
I don't have any forms (just a few TPageProducers), and I'm not willing to settle for that size.
0
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
if it is a CGI application, you proabably aren't using any forms at all.
make sure that Forms isn't in the uses section.
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
The unit 'Forms' is NOT in my uses clause. I am including these units:

cgidisc.dpr:
Uses
  HTTPApp,
  CGIApp,
  main in 'main.pas';

main.pas
Uses
  Windows, Messages, SysUtils, Classes, HTTPApp;

Which should I remove?
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
how big ?

you can exclude the debuginfo (if not done) at
Project|Options|Linker|EXE and DLL Options
turn all off (integrated debugging works also)

this will make the exe ~75% smaller
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
Yes, kretzschmar (nice picture BTW ;-), pressing F5 is potentially dangerous for the question... :-)
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
oops, posted twice :-))

the httpapp-unit uses forms
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
hi nrico

btw. you've also this q posted twice :-))
btw2. thanks for the compliment :-)

well, depending on your code, i guess,
it would be hard to get rid of the forms-unit,
because the cgiapp-unit ->uses httpapp-unit ->uses forms-unit

meikl
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 75 total points
Comment Utility
another idea,

did you thought about to use upx

look at
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html

meikl
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Expert Comment

by:DValery
Comment Utility
I'd recommend to look here:

http://mercury.spaceports.com/~bonanzas/xcl_main_info.htm

I's the fine library for small Delphi projects.
0
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
What is the purpose of Debug info

Motaz
0
 

Expert Comment

by:Zdhanko
Comment Utility
Add {$APPTYPE CONSOLE} directive to
produce console application and
remove directive {$R *.RES} from
project file and use project file
as main programm.
remove from project file strings with "Application" word
begin
{your code here}
Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end;
Doing so size of EXE may be 64KB.
You can also reduce heap stack size.

0
 

Expert Comment

by:Zdhanko
Comment Utility
{file spray.dpr}
program spray;
{$APPTYPE CONSOLE}
uses  SysUtils,Classes,mxarrays,inifiles;
 ...
procedure ReadSprayIni;
begin
....
end;

begin
 ReadSprayIni;
end.
0
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
Zdhanko Didn't you think that he may need Application object? because he uses TWebModule, didn't need intialization?

Sorry Nrico, but I have the same problem, I'm write CGI server side applications using Delphi.

Motaz
0
 

Expert Comment

by:Zdhanko
Comment Utility
My solutiion not for such a program,
but for another types works good.
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
kretzschmar --
  I know I posted the question twice (three times to be correct, but I've already deleted one). It seems that when I press F5, my last post is repeated...
I don't like the UPX idea, I want to keep my executable as "clean" as possible. Plus, it seems UPX has to decompress my EXE, which means it would take extra time and I want to minimize running time, with my eye on the server-timeout.

DValery --
  I don't believe this XCL has any components for Web development.

Hmmm.... looks like I'm stuck with my 328 Kb app.
0
 

Expert Comment

by:vanbeek
Comment Utility
If docking support is not a concern, you might want to compile using D3 instead of D5 (or 4). This will further reduce the size of your applications.
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
I only have D4. I'm afraid that is not an option :-).
0
 
LVL 3

Expert Comment

by:bryan7
Comment Utility
I once got a program source, exe included.. the exe waw 56 KB.. when I compiled the source i got 300 KB .. how he did it ?
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
maybe upx, bryan ;-)

hi nrico,

well, was just an idea, i use it for apps, where the user must do a remote-dial in into network, to reduce the transmission-time. nevertheless, a smaller exe-size saves loadingtime, and
the decompressing is really fast.

meikl
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
kretzschmar, I'll check this UPX out then get back here.
0
 
LVL 1

Author Comment

by:nrico
Comment Utility
Wow, this UPX is really useful! I get at least 50% off of my Delphi EXE's!

Though I'm not going to use it for my CGI project (I don't know if it'll run on the server's platform, which is most likely unix), but I certainly will for my other exe's!

kretzschmar, you'll get the points!
0
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
Please could some one send this page to me and it's contents for example if there is an application or tool.
My stupid proxy won't move me to that site:
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html

Motaz
motaz1@yahoo.com
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now