• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Smaller executable

I'm writing a command line c++ program and I'm using the Borland free command line compiler. How can I get the size of my program down? It's really not doing a whole lot, but it's already up to 250KB. Is there something I can do differently in terms of include files or with variable decalaration to make the size of my executable smaller?

Thanks in advance!
0
dankennedy
Asked:
dankennedy
  • 5
  • 3
  • 3
  • +6
1 Solution
 
AxterCommented:
What type of program is it?  WIN32, DOS Console, ANSI?

Your compiler should have an option for compact compile.
0
 
AxterCommented:
With out knowing more about your application, it's difficult to advise you.

Please provide more details.
0
 
Sys_ProgCommented:
Here is some material explaining that

http://www.catch22.org.uk/tuts/minexe.asp

Amit
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AxterCommented:
Nice link Sys_Prog
0
 
rstaveleyCommented:
Here's the original MSJ article http://www.microsoft.com/msj/archive/S569.aspx
0
 
stefan73Commented:
Hi Sys_Prog,
http://www.catch22.org.uk/tuts/minexe.asp
That's an interesting page.

Cheers,
Stefan
0
 
Sys_ProgCommented:
Yep

I remember having a good link for implementing your own RunTime Function and reducing the executable size by eliminating the library code
But not able to find it now
Anyway, I am searching for it on my disk and would post it if I am successful finding it

Amit
0
 
nonubikCommented:
Maybe it's compiled in debug. In release mode should have a smaller size...
0
 
stefan73Commented:
nonubik,
Not necessarily. Code can get very bloated just by using a couple of STL classes.

Stefan
0
 
mokuleCommented:
May be off topic, but in any case You can pack it with upx.
0
 
stefan73Commented:
mokule,
Yep, upx is nice.

Stefan
0
 
rstaveleyCommented:
...provided you only expect to execute one instance at a time.

http://www.catch22.org.uk/tuts/minexe.asp:

> The disadvantage of this technique is that multiple copies of your program will not share the same memory location, so more RAM is required when running multiple instances.
0
 
waysideCommented:
> How can I get the size of my program down?

Exactly what problem are you trying to solve? Why is a 250K executable causing you problems, as opposed to a 200K exe or 100K exe?

When you can buy 100 Gb+ drives for < $100, I'm not sure it makes sense to spend any time at all trying to squeeze a few kilobytes out of a file. You could be spending this time adding more features to your program. :)

I'd worry more about how much memory the program will use once it's running, this will have a far more noticeable impact than how big it is on the disk.

There is a certain aesthetic I guess in having a small compact program, but I wonder if the benefit is really worth the pain of removing all the CRT calls from your code or writing your own startup function or whatever.
0
 
dankennedyAuthor Commented:
Thanks for all the good links! Let me take a look at them now...

The reason I need a smaller program is because the app I'm trying to write is going to be deployed over the network to MANY computers.  A smaller executable would speed up the deployment process significantly.  I'm sure a program which does what mine does, could be compacted down to least 100K. It's a console app and will run as an NT service.

I'll check out the links you guys posted and get back to you.

Thanks!
0
 
mokuleCommented:
In case You want to look at upx here is a link
http://upx.sourceforge.net
0
 
waysideCommented:
> The reason I need a smaller program is because the app I'm trying to write is
> going to be deployed over the network to MANY computers.

Hmmm - 100Kb smaller * 1000 machines = 100 Megabytes. On a 10 Mbit/second network you save around 100 seconds...

In any case, the best bang for your time IMO is probably to use image compression, you can add it right into your build procedure. UPX is ok, although last time I tried it it did not work with all the exe's I tested it with. I've used one called AsPack in the past which works great, but it it not free.
0
 
waysideCommented:
> The reason I need a smaller program is because the app I'm trying to write is
> going to be deployed over the network to MANY computers.

Hmmm - 100Kb smaller * 1000 machines = 100 Megabytes. On a 10 Mbit/second network you save around 100 seconds...

In any case, the best bang for your time IMO is probably to use image compression, you can add it right into your build procedure. UPX is ok, although last time I tried it it did not work with all the exe's I tested it with. I've used one called AsPack in the past which works great, but it it not free.
0
 
avizitCommented:
While not exactly C++ and also related to Linux/unix etc

The following link might be an interesting read for some of you

http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux

-Abhijit

0
 
rstaveleyCommented:
> http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html

I like that, but here's a 4 byte executable that does the same thing in DOS:

(1) Source code:

debug.scr
--------8<--------
a
mov ax,42
ret

n42.com
r cx
4
w
q

--------8<--------

(2) Assembly creates a file called 42.com:

    debug < debug.scr

There, now, wasn't that useful? :-)
0
 
rstaveleyCommented:
NB: You need that blank line at the end of debug.scr.
0
 
rstaveleyCommented:
What a shame, just checked this and my memory is wrong. Looks like returning with the error level in AL doesn't do the trick. You need it to be:

debug.scr
--------8<--------
a
mov ax,4c42
int 21

n42.com
r cx
5
w
q

--------8<--------

That returns 0x42 as the error level. Sadly that's 5 bytes rather than 4. Code bloat!
0
 
dankennedyAuthor Commented:
Sorry for the delay... Thanks for the help.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
  • 3
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now