Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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)

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!

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.

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.

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
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.

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.

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

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.

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top