Jlouro
Jlouro

Reputation: 4545

EXE, Resource and Code Reduction

How can I reduce resources inside my application? I have tried a number of tricks I have reduce and rewritten code, reduce line number, Reduce comments, Compressed the final EXE, but this is not the way I want to go, Improve the variable type cast, Remove ICONs,BMP,JPG, from inside the application I need my applications to be as small as possible on the final EXE and in general resource consumption. Any more ideas, any good articles on this subject Thanks

Upvotes: 5

Views: 1823

Answers (13)

IceCold
IceCold

Reputation: 21154

UPX and ASPack will create a lot of trouble because antivirus false positive alarms. Kaspersky does that a lot!

Upvotes: 0

cgreeno
cgreeno

Reputation: 32371

I would not spend any time removing comments the compiler strips them out anyway

You could reference your images from an external service(eg Amazon S3)

Upvotes: 9

JosephStyons
JosephStyons

Reputation: 58685

Project -> Options -> Compiler:
===============================
Optimization ON
Debug Information OFF
Local Symbols OFF
Reference Info OFF
Use debug DCUs OFF

Project -> Options -> Packages:
===============================
Build with runtime packages ON (but you will have to distribute your BPLs!)
Note to non-delphi folks:
a BPL is just a DLL, but with magic Delphi dust to make it easier to use.

This article may be useful to you.

Upvotes: 3

Roddy
Roddy

Reputation: 68033

Measure first, THEN optimise. How big is your application, and how big would you like it to be?

Are you concerned about...

The size of the application .EXE file on disk? Then...

  • Build with runtime packages on. You'll get a tiny .EXE, but will need to distribute .bpls as well.

The RAM memory used by the application? Then...

  • Build with runtime packages off - the linker will omit most unused parts of packages.

The size of the application installer? Then...

  • Build with runtime packages off
  • Use Inno Setup
  • Most of the suggestions above?

The size of the application PLUS PACKAGES/DLLS after installation? Then...

  • Build with runtime packages off, and use UPX

Upvotes: 4

PatrickvL
PatrickvL

Reputation: 4164

A nice trick to reduce executable size (actually, PE-image size, as this applies to DLL's too), when relocation is not an issue :

Leave the relocation-info out!

In Delphi, you could do it like this :

// Remove relocation table (generates smaller executables) :
// (See http://hallvards.blogspot.com/2006/09/hack12-create-smaller-exe-files.html)
{$SetPEFlags 1} // 1 = Windows.IMAGE_FILE_RELOCS_STRIPPED

Cheers!

Upvotes: 7

mghie
mghie

Reputation: 32334

Do not create all forms automatically, even though Delphi gives you the option now, and did this unconditionally for new forms in earlier versions. Only create the main form, and use the following (pseudo) code for the showing of modal dialogs:

procedure TMainForm.OptionDialog(Sender: TObject);
var
  Dlg: TOptionDialog;
begin
  Dlg := TOptionDialog.Create(nil);
  try
    // prepare dialog
    if Dlg.ShowModal = mrOK then begin
      // apply changed settings
    end;
  finally
    Dlg.Free;
  end;
end;

This will shorten application loading time and reduce your overall resource usage, especially for complex dialogs with many controls.

Upvotes: 4

Birger
Birger

Reputation: 4353

I always use UPX to compress exe files. It works perfectly, often resulting in a factor 2 compression. And, of course, disable all the debug info will help reduce file size.

Upvotes: 1

Jim McKeeth
Jim McKeeth

Reputation: 38703

Typically speaking if you want a smaller EXE size then go with an earlier version of Delphi.

Upvotes: 2

Harriv
Harriv

Reputation: 6137

Drop the VCL and use KOL and MCK: http://kolmck.net/

This is radical and very big change, but will get the exe size down.

Upvotes: 4

mghie
mghie

Reputation: 32334

Put any images that the program uses more than once into image lists or TGraphic components, and put those into a data module. Link all your components using these glyphs to the image lists. If you use the Object Inspector to add the same glyph to several components you will end up with multiple copies of it, increasing both your loading time and your executable and working set size.

Upvotes: 8

Toon Krijthe
Toon Krijthe

Reputation: 53366

What about switching debug information off in the project options:

  • no debug info
  • no runtime checks
  • reduce number of external units uses if possible.

But debug info kan be a major killer.

Upvotes: 10

Riho
Riho

Reputation: 4593

Is it really worth all this trouble? We are not living in 640 KB memory times anymore.

If you want youre EXE to be smaller then use dynamic linking of packages and libraries. That gives most of the boost. Also put all your resources (images,sounds) into separate DLL. You won't save anything by deleting comments and writing all your code in one long line.

Upvotes: 2

David Schmitt
David Schmitt

Reputation: 59316

Use a memory profiler like the one from Red Gate to get a real time view into the run-time memory usage.

Upvotes: 0

Related Questions