 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Le Chaud Lapin Guest
|
Posted: Tue Dec 12, 2006 10:10 am Post subject: Portable Techniques For Reducing Size Of Binary |
|
|
I would like to know what techniques I can use to reduce the size of my
executable.
Suppose I start with a 556KB. I try various thinks and show the
resulting size after doing that one optimization independently of the
other. My platform is MS Windows, but I am looking for things that can
be done portable in the code without too many #define's.
I have tried the following:
1. Remove linking to standard library (as much as possible) (512KB) *
2. Add throw() to function prototypes - *unfortunately, VS2005 does
not yet support (556KB)
3. Get rid of all GUI elements and go to CUI-only (484KB) with command
loop
4. Set optimizer to favor small size over high speed (516KB)
5. Revisit all template code and make sure functions are not in-line
(not done yet)
Does #5 make help?
*I noticed in the linker symbol output file that there are many
elements from standard library that get linked in. I might have used a
few sprintf's here and there, and a few trigonometric functions, but
the rest...
***Because empty throw specifications [throw()] were not supported, I
forcibly turned off all exception handling using the compiler switches,
and though it cried the whole time while compiling, the resulting
executable was (492KB).
Finally, my goal was to get the smallest size by doing all of these at
once so that there as only the "engine" part of the program and a
skeletal main() having neither a GUI nor a real CUI. (372KB)
But printf, scanf, and math friends are still present, so I have two
questions:
1. Knowing that some global variables will be inevitably linked
because of the standard library, is it worth the trouble to get rid of
scanf and printf and perhaps a few of the math functions assuming there
will be no CUI?
2. What other portable techniques exist for trimming the fat from
EXE's. I have seen Matt Pietrek's article for Windows, but I need
methods that are source code centric and portable.
TIA,
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Robert Mabee Guest
|
Posted: Wed Dec 13, 2006 4:49 am Post subject: Re: Portable Techniques For Reducing Size Of Binary |
|
|
Le Chaud Lapin wrote:
| Quote: | I would like to know what techniques I can use to reduce the size of my
executable.
|
I don't think there's any better way than to study whatever map files
your linker (and related tools) can generate, and get similar info for
each of the individual object files (especially code segment size, as
some data size is duplicated in each object file). Pay no attention
to the total file size as that is mostly symbolic information for
linking and debugging, and won't occupy memory during execution.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Dave Harris Guest
|
Posted: Wed Dec 13, 2006 4:50 am Post subject: Re: Portable Techniques For Reducing Size Of Binary |
|
|
jaibuduvin (AT) gmail (DOT) com (Le Chaud Lapin) wrote (abridged):
| Quote: | 2. What other portable techniques exist for trimming the fat from
EXE's.
|
Try using explicit instantiation of all templates. If you rely on implicit
instantiation, the compiler will probably generate an instantiation in
every compilation unit that uses the template. The linker may be smart
enough to discard all but one of them, but then again it may not. If you
system doesn't yet support throw declarations than it's not exactly state
of the art.
| Quote: | 5. Revisit all template code and make sure functions are not in-line
(not done yet)
|
I doubt this will make any difference.
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|