Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does using boost increase file size so much?

Tags:

c++

size

boost

I've noticed that when I use a boost feature the app size tends to increase by about .1 - .3 MB. This may not seem like much, but compared to using other external libraries it is (for me at least). Why is this?

like image 933
Anonymous Avatar asked Oct 15 '22 10:10

Anonymous


2 Answers

Boost uses templates everywhere. These templates can be instantiated multiple times with the same parameters. A sufficiently smart linker will throw out all but one copy. However, not all linkers are sufficiently smart. Also, templates are instantiated implicitly sometimes and it's hard to even know how many times one has been instantiated.

like image 83
dsimcha Avatar answered Oct 20 '22 20:10

dsimcha


"so much" is a comparative term, and I'm afraid you're comparing apples to oranges. Just because other libraries are smaller doesn't imply you should assume Boost is as small. Look at the sheer amount of work Boost does for you!

I doubt making a custom library with the same functionality would be of any considerable lesser size. The only valid comparison to make is "Boost's library that does X" versus "Another library that does X". Not "Boost's library that does X" and "Another library that does Y."

The file system library is very powerful, and this means lots of functions, and lot's of back-bone code to provide you and I with a simple interface. Also, like others mentioned templates in general can increase code size, but it's not like that's an avoidable thing. Templates or hand-coded, either one will results in the same size code. The only difference is templates are much easier.

like image 24
GManNickG Avatar answered Oct 20 '22 21:10

GManNickG