Re: Ridiculous size of executable?
From: tom_usenet (tom_usenet_at_hotmail.com)
Date: 05/12/04
- Next message: Val: "Little console input problems"
- Previous message: Robert W Hand: "Re: [C][OT] erroneous fprintf output"
- In reply to: Al puzzuoli: "Ridiculous size of executable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 May 2004 12:21:05 +0100
On Tue, 11 May 2004 18:03:32 -0400, Al puzzuoli <alpuzz@comcast.net>
wrote:
>Hi,
>
>I have been out of the programming arena for 10 years or so, and just
>recently, decided to begin dabbling with C++. As one initial exercise,
>I wrote a very simple program to insure that I understood the syntax of
>a for loop. The code compiles and runs, but I noticed that the size of
>the executable is ridiculous, well over 400 kb.
>I am using the Dev-C++ ide and compiler. I am guessing and hoping that
>there are options for optimization that I just haven't learned yet, or
>are my expectations as to file sizes majorly skewed from my experiences
>back in the days of dos? The code I compiled was as follows:
>
>#include <iostream>
>
>using namespace std;
>int i;
>int main ()
>
>{
>for (i=1; i<=10; i++)
>{
>cout <<i <<endl;
>}
>}
C++ executables consist of a number of things stitched together by the
linker.
1. Object code from your own .cpp files. The size of this can vary
with optimization settings.
2. General C++ runtime support code. This includes routines used by
exception handling, new/delete, RTTI, etc. This is generally a fixed
overhead for a particular compiler, and may be reduced by, e.g.,
disabling exception handling (which is generally unwise).
3. Statically linked libraries, including the C and C++ runtime
libraries. In your case this is the problem - the full C++ runtime
library can be 2 or 3MB, and the part linked into your simple
application up to, say, 1MB.
The problem is that by having #include <iostream> a large amount of
the C++ library is being dragged into your executable, since all of
the locales support, streams, etc., etc. is generally pulled in by the
primitive linker technology being used. Carefully written libraries
can minimize this effect (apparently compiling the above to less than
4K is possible with a carefully put together C++ library of which only
one exists that I know of). There's a paper on this stuff here (read
chapter 3 if you're interested):
http://std.dkuug.dk/jtc1/sc22/wg21/docs/PDTR18015.pdf
The easiest way to reduce exe size is simply to dynamically link with
the C++ library dll. However, this gives a false sense of security,
since the memory requirements of your application are probably now
actually increased by having to load that dll, even though your exe is
much smaller than it was.
Tom
-- C++ FAQ: http://www.parashift.com/c++-faq-lite/ C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
- Next message: Val: "Little console input problems"
- Previous message: Robert W Hand: "Re: [C][OT] erroneous fprintf output"
- In reply to: Al puzzuoli: "Ridiculous size of executable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|