From the highest possible performance point of view, does the static vs dynamic library linking option have also impact on performance because of the higher cache-miss ratio for DLL?
My idea is, when a library is statically linked, whole program is loaded on one place or nearby. But when dynamically linked, DLL can be loaded somewhere and it’s variables can be allocated “too far”.
Is it true, or there’s no performance penalty for a DLL in terms of cache miss ratio? (fast C/C++ code only)
“whole program is loaded on once place”: your system’s memory manager will still map executable memory pages onto physical memory to it’s liking – you don’t control that. At run-time, physical pages will be swapped out to disk if other portions of your executable code are needed.
Using a shared library may reduce the number of code pages needed in physical memory when multiple processes can actually share the library.
Summarizing:
NO: dynamic or static linkage does not influence cache-misses directly. Dynamic linkage may reduce cache misses for highly reused libraries.