[Scummvm-devel] ScummVM binary size comparison

Max Horn max at quendi.de
Wed Nov 12 13:41:02 CET 2008


Hi everybody,

Here are some mores idea how to save code size:

== Trim base/commandline.cpp ==

Virtuall all code in that file is not needed on the DS (or any other  
port without a console). AFAICT, the DS only needs the "-c" command  
line option, to choose different config files for the various builds  
with different engines en-/disabled.
Well, these days it shouldn't do that anyway -- just overload  
OSystem::openConfigFileForReading() to return the config file the  
specific build. According to Neil's figures, that could save about 24kb.

Short term, we could add some #ifdef magic to conditionally remove all  
that on those ports; on the long run, we could finally look into  
implementing the idea of a "class Main" replacing much of the code in  
base/main.cpp and base/commandline.cpp, see <http://wiki.scummvm.org/index.php/User:Fingolfin#Misc 
 >


== Disable useless debug() and printf() calls ==
On ports without a console, you usually just drop whatever output  
debug() or printf() are meant to produce (except maybe in debug  
builds, if you can transfer that data of a serial port.
But if one does so by replacing the body of those functions by  
nothing, the calls still remain in the code, and that costs a lot (as  
the message string then is included, too). We could solve this by  
introducing a new (set of) macro(s), like this:
#ifdef DISABLE_DEBUG_OUTPUT
#define SVM_DEBUG(x)	do {} while(0)
#else
#define SVM_DEBUG(x)	debug x
#endif

Then instead of
   debug(1, "foo");
we would write
   SVM_DEBUG((1, "foo"));
(notice the extra set of parentheses) to completely remove any trace  
of that call from the binary. I haven't measured how much this saves  
in total, but for a sample file (common/advancedetector.cpp), it was  
1063 raw bytes of code. Not much. But if we also cover printf and  
warning...


Bye,
Max




More information about the Scummvm-devel mailing list