Originally posted by SystemCrasher
View Post
2) If your binary is larger, runtime memory usage is larger. Well, at least that code/data generally have to be in RAM, right?! (really it more complicated, but idea stays)
Have you investigated the overhead of the dynamic loader ?
3) If you link lib statically... there is no way to see other programs use same lib and only keep single instance of that in memory anymore. Can you imagine, these days all sane OSes around would keep only one instance of dynamic lib code/data as long as they are identical - and so mem usage only grows when copies actually diverge, usually slightly. Static linking obviously breaks this process.
Say, run 10 apps using dynamic Qt - and only 1 instance of Qt would be in memory (+/- small differences of each instance). Run 10 statically linked apps - and you have 10 independent instances of Qt in RAM, not anyhow sharing pages anymore. Just because nobody even knows this code is same or similar. So static linking causes resource hogging.
Say, run 10 apps using dynamic Qt - and only 1 instance of Qt would be in memory (+/- small differences of each instance). Run 10 statically linked apps - and you have 10 independent instances of Qt in RAM, not anyhow sharing pages anymore. Just because nobody even knows this code is same or similar. So static linking causes resource hogging.
If the static library was create in the correct way (which very few are, sadly), you only link in the code that you actually use. Contrary to how dynamic libraries work, where everything gets put in a huge blob.
I think rust have an initiative to create static libraries the correct way. They boast about only pay for what you use.
With the exception of libc, the shared usage of the dynamic libraries are much less than people are led to believe.
Comment