3 ms·
Your program uses one function from a library. If that library is statically linked, that one function is compiled into your program. The rest of the library i
by marcus_holmes 6y ago
Your program uses one function from a library.
If that library is statically linked, that one function is compiled into your program. The rest of the library is ignored.
If that library is dynamically linked, the entire library is loaded into memory, and the function address is shared with your program. More memory used.
The advantage of dynamic linking is if that specific version of the library is already in memory (because another application is using it) then it takes up no additional memory. Less memory used.
- quotemstr 6y ago> If that library is dynamically linked, the entire library is loaded into memory, and the function address is shared with your program. More memory used. False. Shared library pages, like pages in executables, are loaded only on demand. You pay a memory cost for what you use, not what's available.
- naniwaduni 6y ago... at page granularity.
- cma 6y agoI'm pretty sure Linus was talking about the fixups to the function addresses that happen at load time. Because those pages are modified, they aren't shared with other instances of the same process (unless those processes forked from same parent after the shared library was loaded?), causing more memory usage and less cache locality than static linking: https://en.m.wikipedia.org/wiki/Relocation_(computing) https://en.m.wikipedia.org/wiki/Relocation_(computing)
- dooglius 6y ago> If that library is statically linked, that one function is compiled into your program. The rest of the library is ignored. At least for gcc, this isn't true unless you pass some obscure flags in; the whole .a gets pulled in