Jump to content
  • Advertisement
Sign in to follow this  
Endar

Codebloat and templates - big deal?

This topic is 4221 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

For my last engine, I was compiling it to a static library, the debug version of which actually came to a total of 18mb and the release version came to 16mb. For one part, I'm actually generating a total of 22 template classes using boost preprocessor magic. They're not very big themselves, but they do use other parts of the boost libraries. Is it possible that generating these 22 classes and using them is causing such ridiculous sizes for the libraries? I think I'm also using RTTI. Does this have a big impact on the size of a program or library? PS. For those who don't know, the dll of the Irrlicht open source graphics engine (version 1.0) is a total of 1.5mb, and it does approximately 22079460347 times better than mine (just an approximation of course :D ).

Share this post


Link to post
Share on other sites
Advertisement
More importantly - how big is a release executable linked against that static library?

Did you strip out all debug information & symbols?

I doubt templates are taking up ~20mb. Code is pretty small.

And which boost libraries are you using?

Share this post


Link to post
Share on other sites
With a program that big it has to be due to a declaration of a large static array, not code bloat.

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
With a program that big it has to be due to a declaration of a large static array, not code bloat.


I have a single static class, which isn't very big at all. It's members are an integer and a dynamic array, which allocates the array space on the heap.

That's it. I have a lot of stuff with the word "static" in their names (not the keyword), but they have nothing to do with actual static variables.


Quote:
Original post by RDragon1
More importantly - how big is a release executable linked against that static library?

Did you strip out all debug information & symbols?

I doubt templates are taking up ~20mb. Code is pretty small.

And which boost libraries are you using?


I've compiled a basic tetris game (not completed) that uses my engine, and it is a total of 560kb with the library being 16mb.

I was also fairly sure that code is pretty small, but I was a little afraid that generating classes at compile time could rack up some space issues.

Okay, boost libraries. Do you mean actual libraries that I'm linking to? Because I'm linking only to the boost::regex library, but I'm #includ'ing a whole bunch of stuff to use:

  • boost::format
  • boost::variant
  • boost::regex
  • boost::preprocessor
  • boost::lexical_cast
  • boost::tuple
  • boost::type_traits
  • boost::function
  • boost::bind

So, with these ones, I'm simply including the headers, with the exception of regex, which I'm linking against it's library.

Yes, I'm as sure as I can be that I've set it to not include debug information. I've taken a look at the settings at anything that looks like it's associated with debugging, and it is all "no" for compiling a release version (and I did re-compile the library in release configuration).

Share this post


Link to post
Share on other sites
the word "static" is extremely overloaded in the programming world. When they said it must be due to a large static library, they did not mean any code you have written yourself ... they meant code someone else had written, that you use, that is linked into your library or program statically (as a static library versus a dynamic link library).

For example the microsoft visual c++ runt time is about 0.5 mb, and the libc is about 2.5 mb ... many libraries are larger ...

besides boost, what do you link to in your program?

Share this post


Link to post
Share on other sites
Apart from boost? I link to the OpenGL libraries, the standard C++, and probably C stuff. I use tinyxml, but I'm compiling the source for that, and not linking to a library. Also the stuff for compiling windows programs using VC++ express.

That's it. Nothing special or unusual as far as I know.

Share this post


Link to post
Share on other sites
Quote:

I've compiled a basic tetris game (not completed) that uses my engine, and it is a total of 560kb with the library being 16mb.


Your executables are normal size - but your library is huge. What's probalby happening is that your library is full of stuff that's never being used - it's generally not a good idea to put explicit template instantiations in libraries, as they increase the size of the library even if they aren't used. Just stick with a header only library for template classes.

FYI, when your linker creates executables using your library, it only includes the code that's actually used, throwing away all the junk.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nitage
Quote:

I've compiled a basic tetris game (not completed) that uses my engine, and it is a total of 560kb with the library being 16mb.


Your executables are normal size - but your library is huge. What's probalby happening is that your library is full of stuff that's never being used - it's generally not a good idea to put explicit template instantiations in libraries, as they increase the size of the library even if they aren't used. Just stick with a header only library for template classes.

FYI, when your linker creates executables using your library, it only includes the code that's actually used, throwing away all the junk.


For statically linked libraries, yes. For dynamically linked libraries, it basically doesn't include anything - but you have to keep a copy of the DLL around in order for the exe to work :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Nitage
Your executables are normal size - but your library is huge. What's probalby happening is that your library is full of stuff that's never being used - it's generally not a good idea to put explicit template instantiations in libraries, as they increase the size of the library even if they aren't used. Just stick with a header only library for template classes.

A header only library for template classes? I'm not quite understanding that. The template classes are being generated in a header file, but of course are being included in source files.

Quote:
Original post by Zahlman
For statically linked libraries, yes. For dynamically linked libraries, it basically doesn't include anything - but you have to keep a copy of the DLL around in order for the exe to work :)

You don't have to keep a copy of the library around when you're using a static library?

Share this post


Link to post
Share on other sites
In this case, static vs dynamic is referring to compile time vs run-time. A static library is linked at compile time, so the code is copied into the resulting executable (and there might even be some optimizations around the call boundaries). A dynamic library is linked at run-time, by the executable telling the operating system to load the dynamic library into its memory and locating the required functions. This allows the library to be replaced by a newer version without having to recompile; thus, the linking is more dynamic.

Only dynamic libraries are needed at run-time. The needed parts of static libraries were already inserted into the executable.

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!