Thread: Program size problem

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Program size problem

    Yesterday, when I compiled the same program, the size of it was about 450 kb-s, today when I use the same file, it takes 1250kb. I tested a bit, when I included windows.h yesterday, the size of the program remained, but today it adds 650kb-s to the file size, but including iostream always adds 450kb-s. What does the windows.h include to my file, that isnt necessary?
    Sorry for my bad english :P

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    Probably a whole lot of junk. Did you also check that it is not in debug mode?

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Considering the entire windows api is declared in windows.h, it includes a lot. there is a macro you can use: WIN32_LEAN_AND_MEAN or something like that to cut out stuff that people generally don't use. But the upside is it adds 650or so amount of data to start out with, but does not increase any more. So your program size will now grow as you add stuff which should be fairly slowly.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    including windows.h does not affect the final size of the program at all. The linker only pulls the functions that you use in your program, and the functions/data that those functions reference, into your executable program. As with any library, the linker does NOT add everything in the library to your program. If that were the case, every program you write would be very very huge.

    using a macro such as WIN32_LEAN_AND_MEAN also does not affect the size of the final program, it only helps speed up the compiling process (preprocessor) by not including some of the seldom-used header files.

    So the most likly cause of the program size difference is between release and debug mode compiles, as sand_man suggested. including windows.h, by itself, will not cause that behavior.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Yes it started after I turned the debug mode on. But after that, when I turned it off, the progs are still 1.25mb-s. HELP! I am going to reinstall my Dev-C++ because of that.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    I dont't know if that works with windows-exes produced by g++.
    Running strip on the executables reduces the size a lot.
    Kurt

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    are you certain you are looking at the right *.exe file? maybe you need to delete all *.o files in the project directory then rebuild everything. There might be some object files build for debug and others build for release.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    including iostream always adds 450kb
    (Do you mean 450KB? or 450Kb? Probably the former.)

    On my Dev-C++ 4.0, it adds about 15KB.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    After reinstallation the size is back normal.
    But iostream still adds 450KB-s to the size.
    Without any header file, programs are 16KBs.
    Last edited by maxorator; 09-18-2005 at 12:55 AM.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    But iostream still adds 450KB-s to the size.
    That's unfortunate, but at this point and in this case it is normal. Read the MinGW FAQ on "Why is my C++ binary so large?", since Dev-C++ uses the MinGW port of GCC by default. If after using strip the executable size is still too large, you may consider using UPX.

    On my Dev-C++ 4.0, it adds about 15KB.
    But Dev-C++ 4, aside from being outdated itself, uses an outdated compiler set.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    `strip' undeclared (first use this function)

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well then declare it!

    What are you talking about? Do you have the wrong thread?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by dwks
    Well then declare it!

    What are you talking about? Do you have the wrong thread?
    Thats the error what I get when I use that strip thing from that link I got.

  14. #14
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by laserlight
    That's unfortunate, but at this point and in this case it is normal. Read the MinGW FAQ on "Why is my C++ binary so large?", since Dev-C++ uses the MinGW port of GCC by default. If after using strip the executable size is still too large, you may consider using UPX.


    But Dev-C++ 4, aside from being outdated itself, uses an outdated compiler set.
    That means Dev-C++ 4 is much better than Dev-C++ 4.9.9.2!

  15. #15
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by maxorator
    `strip' undeclared (first use this function)
    It's strip.exe and it should be in your compilers bin folder.
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Problem in getting size of a window
    By axr0284 in forum Windows Programming
    Replies: 3
    Last Post: 02-22-2005, 06:15 PM
  3. Replies: 11
    Last Post: 03-25-2003, 05:13 PM
  4. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM