Jump to content
  • Advertisement
Sign in to follow this  
Decrius

[C++] Library / executable size, its large!

This topic is 3320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently developing a small library, 8k code lines at the moment, but the output size stunned me a bit. It used to be 800 kB, but now I added some more template stuff it got up to 1.40 MB. The executable using the library including some OpenGL, Corona, FreeType2 and SDL has a size of 1.90 MB. Note, I'm statically linking to everything but SDL. Both compiled using GCC on WinXP, with -s and -O2. How does this compare to other C++ libraries? Is it large? What is large? How large are your libraries? Also, why is C++ so large compared to C? I really wonder. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Firstly, templates can sometimes just bloat your code. There is a copy of every template function for every type used as template parameters. Depending on what you are doing, you can easily end up with much more code than you really needed. ie.
Foo<float> ( 1.0f );
Foo<double> ( 1.0 );
even though floats and doubles are 99% of the time going to provide the same functionality (discounting need for precision). (that 1% is in my mind when you want to do something specific that takes into account the precision or bit layout to do some interesting trick like the inversesqrroot trick)

Secondly, as a static library not as much code is removed as in a basic executable. The compiler has to assume that unused functions may actually be something called at a later point by whatever executable that links in the library.

Thirdly, I'd venture a guess that the SLD, FreeType2, Corona, OpenGL libraries all together are much larger than 1.9Mb. When compiling the final executable the compiler will start throwing out anything that isn't explicitly used in the code shrinking the size of the end product to less that the sum of the parts in most cases.

Also, C++ isn't "large compared to C" unless you are using features in C++ that aren't available in C. Something like

struct Object { ... };
Collate( Object *pObj );

isn't going to produce more code than

class Object
{
...
Collate( );
};

BUT

template <typename T> Foo( T *pBar ) {...}

could end up producing a lot of code. But no more so than if you wrote out manually:
Foo( int * ){...}
Foo( char * ){...}
Foo( float * ){...}
... etc.

Share this post


Link to post
Share on other sites
It's not very large imo if you are using static dll linking... i've seen 3-4 mo, evnt 7-8 mo .exe(games mostly), probably because of those static dlls and/or also because of a large ressources file... If you're dll make 1 Mo and you are linking staticly, that's normal that you're program make 1.5mo, try dynamic linking if you want a small .exe. It's also normal to have a large dll if you are using #includes wich contain a lot of code.

Share this post


Link to post
Share on other sites
Large static libraries (*.lib) are really not a concern. They typically hold *everything*, and usually compress very well. I've seen *.lib files get into hundreds of MB apiece (take a look at boost, for example).

Share this post


Link to post
Share on other sites
What do you mean by a static DLL? Just static linkage or a DLL which also has a static lib (where the static lib connects the DLL with the executable, right?)?

So a few MB's is nothing to concern about? It's a GUI library, not sure how big other libraries are, but GUIchan is about 800 kB, and boost is for me 12 MB...

Share this post


Link to post
Share on other sites
Is it a debug mode exectuable. Debug mode executables are also fairly larger than their release mode counterparts.

Also the C++ complier have an option to favour size over speed if size is really a concern.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!