Why using boost increases file size?

I noticed that when I use the enhance function, the size of the application tends to increase by about 0.3 MB. This may not seem like much, but compared to other external libraries this is (at least for me). Why is this?

+4
source share
4 answers

Boost uses templates everywhere . These templates can be created several times with the same parameters. A smart enough linker will throw everything except one copy. However, not all linkers are smart enough. In addition, templates are sometimes created implicitly, and it's hard to even know how many times an instance has been created.

+4
source

โ€œas muchโ€ is a comparative term, and I'm afraid you are comparing apples to oranges. Just because other libraries are smaller doesn't mean you should assume that Boost is just as small. Look at the huge amount of Boost works for you!

I doubt that creating a custom library with the same functionality will be significantly smaller. The only valid comparison is the โ€œBoost library that makes Xโ€ compared to the โ€œOther library that makes Xโ€. Not the "Boost library that makes X", and the "Other library that makes Y".

The file system library is very powerful, and that means lots of features and lots of back bone code to provide you and me with a simple interface. In addition, like the other templates mentioned in general, you can increase the size of the code, but this is not like what can be avoided. Templates or manual code, one of which will lead to the same size code. The only difference is that the templates are much simpler.

+1
source

It all depends on how it is used. Since Boost is a bunch of templates, it invokes a union of member functions for each type used. If you use boost with n types, member functions are defined (using C ++ templates) n times, one for each type.

0
source

Boost consists primarily of very generalized, and sometimes quite complex patterns, which means that types and functions are created by the compiler as necessary, and not just by declaration. In other words, a small amount of source code can generate a significant amount of object code to execute all variants of templates declared or used. Boost also depends on standard libraries, pulling out these dependencies. However, the most significant contribution is the fact that the Boost source code exists almost exclusively in include files. The inclusion of standard c include files (outside of the STL) usually includes very little source code and contains mostly prototypes, small macros, or type declarations without their implementation. Boost contains most of its implementations in its include file.

-one
source

Source: https://habr.com/ru/post/1299172/


All Articles