开销DLL [英] Overhead of DLL

查看:165
本文介绍了开销DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很基本的问题。


  1. 当库只由一个进程使用。是否应该将其保留为静态库?

  2. 如果我将该库用作DLL,但只有一个进程使用它。 **

几乎

em>没有开销有一个单独的DLL。基本上,从DLL导出的函数的第一次调用将运行一个小的桩,修复函数地址,以便通过跳转表通过单个跳转执行后续调用。 CPU的工作方式,这个额外的间接几乎是免费的。



主要的开销实际上是一个机会成本,而不是一个开销本身。也就是说,现代编译器可以做一些称为整个程序优化的操作,其中整个模块(.exe或.dll)在链接时立即编译和优化。这意味着编译器可以在整个程序的所有.cpp文件中执行调整调用约定,内联函数等操作,而不仅仅是在一个.cpp文件中。



这可以产生相当不错的性能提升,对于某些类型的应用程序。但是,整个程序优化不能跨越DLL边界发生。


I have a quite basic question.

  1. When a library is used only by a single process. Should I keep it as a static library?
  2. If I use the library as a DLL, but only a single process uses it. **What will be the overhead?*

解决方案

There is almost no overhead to having a separate DLL. Basically, the first call to a function exported from a DLL will run a tiny stub that fixes up the function addresses so that subsequent calls are performed via a single jump through a jump table. The way CPUs work, this extra indirection is practically free.

The main "overhead" is actually an opportunity cost, not an "overhead" per-se. That is, modern compilers can do something called "whole program optimization" in which the entire module (.exe or .dll) is compiled and optimized at once, at link time. This means the compiler can do things like adjust calling conventions, inline functions and so on across all .cpp files in the whole program, rather than just within a single .cpp file.

This can result in fairly nice performance boost, for certain kinds of applications. But of course, whole program optimization cannot happen across DLL boundaries.

这篇关于开销DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆