Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effect of DLL to execution speed

Tags:

c++

dll

First of all, I use user-defined header and corresponding cpp file. Then I include and so on. If I would switch to DLL, would the execution speed of the code be retarded?

Secondly, I know that in "DLL", "D" represents "dynamic" however, my friend said that there are two ways to use them: Statically and dynamically. If it is dynamic already, what we have to do with "static"?

like image 371
Shibli Avatar asked Feb 26 '12 20:02

Shibli


People also ask

Are DLLs fast?

Unless the function is very small (so it gets inlined otherwise), using a DLL has no difference whatsoever on the performance (aside from the fact that loading a DLL does increase the startup time of your application.)

What is the main reason for using DLLs?

The use of DLLs helps promote modularization of code, code reuse, efficient memory usage, and reduced disk space. So, the operating system and the programs load faster, run faster, and take less disk space on the computer. When a program uses a DLL, an issue that is called dependency may cause the program not to run.

What happens when you load a DLL?

Every process that loads the DLL maps it into its virtual address space. After the process loads the DLL into its virtual address, it can call the exported DLL functions. The system maintains a per-process reference count for each DLL. When a thread loads the DLL, the reference count is incremented by one.

What is the purpose of .DLL file in C #?

In Windows, a dynamic-link library (DLL) is a kind of executable file that acts as a shared library of functions and resources. Dynamic linking is an operating system capability. It enables an executable to call functions or use resources stored in a separate file.


2 Answers

Unless the function is very small (so it gets inlined otherwise), using a DLL has no difference whatsoever on the performance (aside from the fact that loading a DLL does increase the startup time of your application.) Large, performance-critical applications use DLLs (for instance the Intel Math library.) There are minor penalties if the compiler cannot do whole-program optimization, but these are very small differences which usually don't matter.

Regarding static/dynamic: I assume he means that you can link against a DLL the normal way (by using an import library), which forces it to be always loaded or load it dynamically at run-time (using LoadLibrary and dlopen.) No performance difference there, but using LoadLibrary allows you to delay loading the library until actually needed.

like image 193
Anteru Avatar answered Oct 19 '22 04:10

Anteru


  1. Productivity shouldn't regress, as far as calling function from dll in general similar to local function call.

  2. Two types of libs exists:

    • from one poin of view, dynamic libs and static libs. Here static means, that all code from the lib will be linked statically to your exe, oppositely dynamic lib allows to separate code from executable to shared library, that code will be loaded dynamically.
    • Then, dynamic libary can be linked to statically, and that means, that OS will link library to your program on startup and dynamically, that means, you obtain pointers to symbols, storied in library, by hands. While dynamic loading gives more flexibility, it more difficult way that using static linking.
like image 2
Lol4t0 Avatar answered Oct 19 '22 04:10

Lol4t0