#1
  1. No Profile Picture
    Thread Killer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Missouri
    Posts
    41
    Rep Power
    12

    Question How do I reduce the filesize?


    I have built a simple hello world program using M$ Vis C++ 6, and the filesize is about 173KB. This seems outrageous for a program that only prints a line of text to the screen. The only include is iostream.h.

    I have created an empty application that only has void main() {}, no includes, and the filesize was about 150KB. What is this extra space and how do I get rid of it?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,473
    Rep Power
    15
    Hi,

    I use VC++ 6 too. You can reduce the file size on the order of 70% by building a release version of your code. The debug version has all kinds of stuff that VC++6 uses so you can run the debugger. Look at Build/Set Active Configuration.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    138
    Rep Power
    12
    Try using putchar instead of printf or cout. I'm pretty sure putchar has a smaller footprint if you don't use any of the better functionallity.You may want to use low level OS write to files for output etc. as the code for the write is in the OS not your executable.

    Calls to any library functions will add a large constant amount of code. So if you call a function once the code will dramatically increase. The second call should increase the code by almost nothing.

    Also I'm pretty sure if you compile a c program as c++ the output will be larger. All depends on the compiler. It's worth testing.
    --

    ngibsonau
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    London
    Posts
    349
    Rep Power
    12
    Yeah make as a release, and not debug.
  8. #5
  9. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    In addition to what has already been stated, take a look at the compiler options. There are settings you can change that make the code smaller at the cost of speed. I would assume by default that these settings are set to produce faster code at the cost of larger size.
  10. #6
  11. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    elyk>>void main

    you use a VOID main function. Don't you know how wrong that is?

    'Under C89, the return statement at the end of main() is required, whereas under C99 if no return statement is present, return 0 is implied. However, it is good programming practice to always use a return statement, even if you don't have to.'

    It is advisable to use the C99 standard, under which only these are acceptable:

    int main ( int argc, char *argv[] )
    int main (void)
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    12
    Some of the problem comes from using the standard template library. These libraries are great, producing fast code and shorter development times. Unfortunately nothing in life is free. The libraries are bulk your code something horribly, especially when the program logic itself is relatively small.

    One solution is to forgo the STL and write only in C (but then why use C++ at all?). You'll need to weigh execution and development time against file size.

    On UNIX you can also strip the binaries after you create them. This removes some symbol tables that aren't necessary for execution in most cases. There may be hidden costs to this, and I have seen cases where it made no significant impact on file size. I suspect that it's possible to strip executables under windows as well, but I haven't the slightest idea how it's done.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  14. #8
  15. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    Forgot to mention that

    #define VC_EXTRALEAN //MFC apps


    #define WIN32_LEAN_AND_MEAN //non MFC apps

    can help to reduce the size of WIN32 apps.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo