Archived

This topic is now archived and is closed to further replies.

NaliXL

What makes a small program?

Recommended Posts

NaliXL    120
Or, what makes an executable grow bigger? Say that if I want to write a 64K OpenGL demo, what kind of things would I have to keep in mind while programming, not looking at things like textures etc, but really coding techniques? For example : does a "uses" (a.k.a. include) statement to unused code enlarge my executable, or will the compiler ignore it, as it is not used? BTW : I''m using Borland Delphi to code my programs, if that makes any difference...

Share this post


Link to post
Share on other sites
dusik    133
I tellz you what. Depends on the compiler. Delphi is awesome though. I think you''re fine. MSVC++ 6 is also rather decent.

Good compilers don''t include code that is guaranteed not to be used in the EXE. When you use some of the functions from the standard includes, you may unknowingly drag in a whole chain of functions that the function you used depends on.

Example (in C++): including iostream.h makes your file grow by something like 350k. Crazy stuff. (that''s one of the reasons I don''t normally use streams).

I''m not sure what units the size of a delphi app would depend on, but I think delphi apps are quite large in general, since they include a whole visual library. For a simple programme, you''re looking at something like 400 KB at least.

BTW, why would you care about the EXE size anyway?

------------------------
CRAZY_DUSIK* pCrazyDuSiK = new CRAZY_DUSIK;
pCrazyDuSiK->EatMicroshaft(MS_MUNCH_BILL_GATES | MS_CHEW_BILL_GATES);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
If you want to do a 64kb program, the best is that you program in win32 asm, using TASM5 or MASM32, and you need to aply techniques of optimization of size, and to use ONLY the part of opengl libraries what you need.
Sorry of my english

Share this post


Link to post
Share on other sites
Kylotan    9853
quote:
Original post by dusik
Example (in C++): including iostream.h makes your file grow by something like 350k. Crazy stuff. (that''s one of the reasons I don''t normally use streams).

It is not that much. Try a cout "hello world" vs an printf "hello world" and you''ll see the difference is less than 200k, and that''s in debug mode. With optimisations on it''s likely to be even less.



[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post


Link to post
Share on other sites
echeslack    122
i honestly know nothing of delphi, but the most obvious answer to reducing executable size would be to dynamically link to as many things as possible, i.e. leave as much code outside of your executable as possible. more demo oriented sites might have more information about this, maybe cfxweb.net or similar?

ewen

Share this post


Link to post
Share on other sites
burp    122
I''ve been doing contract work in delphi the past few months again so I''ll put in my 2 cents.

Lets say we have a tiny delphi app like this


  
program Project2;

uses
Forms,
Unit1 in ''Unit1.pas'' {Form1};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.


Tiny huh? Not, it''s 307KB

But if you drop the uses Forms and the other code, its only 17KB, better huh, so you will have to get a window the manual way, that should keep the size down.

Also have a look at these links

http://www.theproduct.de/index.html
http://upx.sourceforge.net/

Share this post


Link to post
Share on other sites
Alimonster    185
Another tiny tip: if you comment out the "{$R *.RES}" bit then you save an extra KB or two, because the icon won't be linked in.

I seem to recall that using "Math" whacked up the size of my demos a bit. If you can write replacements for those (maybe in assembler, just the things you need) then you might be able to squeeze another few k. I can't remember the smallest exe I've produced using Delphi, but it was under 10KB without using UPX.

Avoid the VCL if at all possible! For some of my effect exes I used TMemoryStream and TFileStream to load in the pictures, which meant I had to use the "classes" unit. This increased the size by about 40KB!

UPX should give you lots of extra free space. It shouldn't be that hard to do the things you want.

Alimonster
my web site

There are no stupid questions, but there are a lot of inquisitive idiots.

[edited by - Alimonster on March 18, 2002 6:46:29 AM]

Share this post


Link to post
Share on other sites
NaliXL    120
quote:
Original post by Alimonster
which meant I had to use the "classes" unit. This increased the size by about 40KB!


Which means I shouldn''t use classes at all? Shame. They''re very useful sometimes..

Share this post


Link to post
Share on other sites
Alimonster    185
I didn't mean classes as in:

type
TSomething = class
private
public
end;


...but the actual uses unit called "classes". Of course, your mileage may vary. However, keep an eye on your exe size if you do use that unit! The VCL ain't written with size in mind.

[edited by - Alimonster on March 18, 2002 7:07:29 AM]

Share this post


Link to post
Share on other sites
NaliXL    120
quote:
Original post by Anonymous Poster
If you want to do a 64kb program, the best is that you program in win32 asm, using TASM5 or MASM32, and you need to aply techniques of optimization of size, and to use ONLY the part of opengl libraries what you need.

For now, I''ll stick with Delphi. That''s difficult enough for me right now. I''ll think I''ll try assembler when I''m sure I know delphi from a to z.

Share this post


Link to post
Share on other sites
burp    122
Happy birthday Alimonster, nice site

Delphi programmers looking for max performance should know that its compiler is not designed with the game developer in mind.

quote:

Delphi Help File - Optimization

All optimizations performed by Delphi''s Object Pascal compiler is guaranteed not to alter the meaning of a program. In other words, Delphi performs no "unsafe" optimizations that require special awareness by the programmer.



This means that the compiler maintains a very literal translation between the source code and the final output, much like the output from a C++ compiler in debug mode.

This fact makes it even more important to understand asm, if you''re trying to get max performance with delphi.

Share this post


Link to post
Share on other sites
Alimonster    185
quote:
Original post by burp
Happy birthday Alimonster, nice site


Thanks!

The inline assembler with Delphi is a bit crummy in most versions. This expert lets you write MMX/3D-Now!/SSE code in versions prior to Delphi 6.

Another quality optimisation tip: have a crappy processor - it forces you to make things quick .

Alimonster

There are no stupid questions, but there are a lot of inquisitive idiots.

Share this post


Link to post
Share on other sites
a person    118
if you want the most control, liek said before, learn asm. there is NO way you can get a compiled app written in delphi or c/c++ to be of comparable size to a asm written app. DONT use ANY libraries except opengl, and even with that you should link dynamically. with win32 stuff, again link dynamically. you MUST keep the number of libraries your dependent on to a minium. also you will have to generate texture data and sound data at load time. becareful of function use, too many small functions that are not used much will greatly bloat your app. also using things like UPX is good, but custom coded compressor will probably work slightly better since you know what you are compressing.

since you say your not ready for asm, i would suggest not attempting to write a 64k intro, since its virtually impossible. you will be fighting more with the compiler then doing anything useful. write some standard demos first and get comfortable with that.

Share this post


Link to post
Share on other sites
Kylotan    9853
quote:
Original post by a person
there is NO way you can get a compiled app written in delphi or c/c++ to be of comparable size to a asm written app.

Not true. You can generate 4K C++ applications if you know what you're doing.


[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

[edited by - Kylotan on March 20, 2002 3:27:05 PM]

Share this post


Link to post
Share on other sites