美文网首页
Static Libraries vs. Dynamic Lib

Static Libraries vs. Dynamic Lib

作者: cc_Jumper | 来源:发表于2018-07-28 14:40 被阅读14次

    Functions are blocks of code that are reusable throughout a program. Using them saves time, removing the need to rewrite code multiple times. Libraries, like functions also save time in that they make functiones reusable in multiple programs.

    Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries on the other hand, exist as separate files outside of the executable file.

    The downside of using a static library is that it’s code is locked into the final executable file and cannot be modified without a re-compile. In contrast, a dynamic library can be modified without a need to re-compile.

    Because dynamic libraries live outside of the executable file, the program need only make one copy of the library’s files at compile-time. Whereas using a static library means every file in your program must have it’s own copy of the library’s files at compile-time.

    The downside of using a dynamic library is that a program is much more susceptible to breaking. If a dynamic library for example becomes corrupt, the executable file may no longer work. A static library, however, is untouchable because it lives inside the executable file.

    The upside of using a dynamic library is that multiple running applications can use the same library without the need for each to have it’s own copy.

    Another benefit of using static libraries is execution speed at run-time. Because the it’s object code (binary) is already included in the executable file, multiple calls to functions can be handled much more quickly than a dynamic library’s code, which needs to be called from files outside of the executable.

    What does this mean in practical terms? Well, imagine you’re a devloper who has issued an application to thousands of users. When you want to make a few updates to the app, would you rather have to re-issue the entire program, or would you rather just issue updates in the form of modified libraries? The answer depends on the downsides your application can afford. If you have a lot of files, multiple copies of a static library means an increase in the executable file’s size. If, however, the benefits of execution time outweigh the need to save space, the static library is the way to go.

    这里主要是Mark下,方便后续查阅。内容全引用自https://medium.com/@StueyGK/static-libraries-vs-dynamic-libraries-af78f0b5f1e4

    相关文章

      网友评论

          本文标题:Static Libraries vs. Dynamic Lib

          本文链接:https://www.haomeiwen.com/subject/wqyomftx.html