gpt4 book ai didi

c - 内存和静态/共享库中的程序位置

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:49 24 4
gpt4 key购买 nike

当我运行一个程序(在 Linux 中)时,它是否全部加载到物理内存中?如果是这样,使用共享库而不是静态库是否有助于缓存?一般来说,什么时候应该使用共享库,什么时候应该使用静态库?如果重要的话,我的代码要么用 C 编写,要么用 C++ 编写。

最佳答案

article点击涵盖了您想要的一些不错的基础。这article更深入地了解共享库的优势

SO 也深入讨论了这个话题

Difference between static and shared libraries?

When to use dynamic vs. static libraries

几乎所有上述提到的文章都偏向于共享库。维基百科试图挽救静态库:)

来自 wiki ,

There are several advantages to statically linking libraries with anexecutable instead of dynamically linking them. The most significantis that the application can be certain that all its libraries arepresent and that they are the correct version. This avoids dependencyproblems. Usually, static linking will result in a significantperformance improvement.

Static linking can also allow the applicationto be contained in a single executable file, simplifying distributionand installation.

With static linking, it is enough to include thoseparts of the library that are directly and indirectly referenced bythe target executable (or target library).

With dynamic libraries, theentire library is loaded, as it is not known in advance whichfunctions will be invoked by applications. Whether this advantage issignificant in practice depends on the structure of the library.

关于c - 内存和静态/共享库中的程序位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10110160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com