Thread: Help! Why are my programs so big?

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    4

    Unhappy Help! Why are my programs so big?

    I use Dev-C++ from Bloodshed Software.
    When I only include stdio.h the programs have about 30k but when I include only iostream.h the programs have 450k!

    Currently I have program in work with about 100 lines of code. I inlcude stdio.h, time.h, math.h (need this for sqrt) and algo.h (need this for rand()). The compiled executable has 450k.
    Why, the hell, why?!

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    If you want, you could add -s to your compiler options.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    14
    Originally posted by alpha
    If you want, you could add -s to your compiler options.
    Could you please explain that for me? I have no idea how it works and what it does, I would just like to know what "-s" does.

  4. #4
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    >Could you please explain that for me?
    Perhaps you should RTFM before asking for clarification.

    >I would just like to know what "-s" does.
    Right out of the manual:
    Code:
    -s 
        Remove all symbol table and relocation information from the executable.
    p.s. What the alphabet would look like without q and r.

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    4
    Now I know, it's that damn compiler (mingw32.dll?).
    I compiled the same code with Borland C++5 - the executables where 83k and 28k in size (in contradiction to 450k each with dev-c++) and nearly DOUBLE as fast.

    Ok, can anyone recommend me a compiler that does it's work about that good or even better?
    What about lcc or djgpp?

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    4
    I measured the speed with clock().
    The speed difference is very noticeable even without clock().

    To the I/O:
    The program calculates Pi (with the Monte-Carlo-Method) and the only output is the number of points in circle/off circle and Pi after the calculation.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    On my compiler(gcc 3.2), a program that prints "Hello" on the screen in C++ is 12.7 kb, while its C equivalent is 11.3 kb(these are Linux ELF binaries). If you're programming for Windows, the best compilers to use are Borland's and Microsoft's. Even with a not-so-good compiler, 30kb to 450kb difference is pretty massive...are you sure the only difference is the inclusion of <iostream> and <stdio.h>(and the dependant code)?

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    4
    Of course I looked into the compiler options but everything looks fine there. Optimisation is on the highest level.

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    20
    Often times a simple command line "strip <executable>"will work to get the executable size down by stripping the debugging information. DJGPP is for DOS and it provides very large executable files itself. The reason linux ELF binaries are smaller is that GCC links the executable with quite a few library files so that the resulting code does not have to be reinstered into every executable and thus taking up less space.

  10. #10
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    I have the same problem with Dev-CPP. My way of solving it is as follows :

    When writing a code, don't create a new source code, create a project, seems to really help. Also, update the compiler every so often with VRoach ( Launch the compiler, and find Update somewhere in the menus ).

    I cut a 547k program I wrote to 78k with these methods...

  11. #11
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    but when I include only iostream.h the programs have 450k!
    Just a little thing, it should be <iostream> not <iostream.h>
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reroute where programs write to
    By willc0de4food in forum C Programming
    Replies: 7
    Last Post: 09-21-2005, 04:48 PM
  2. How come Dev C++ cant run some programs??
    By Sephiroth in forum C Programming
    Replies: 41
    Last Post: 09-17-2005, 05:35 AM
  3. Way to get the current open programs displayed?
    By CPPguy1111 in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2005, 12:24 AM
  4. Communication between programs?
    By johny145 in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2005, 10:14 PM
  5. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM