Shibli
Shibli

Reputation: 6149

Effect of DLL to execution speed

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"?

Upvotes: 7

Views: 6163

Answers (2)

Anteru
Anteru

Reputation: 19384

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.

Upvotes: 14

Lol4t0
Lol4t0

Reputation: 12547

  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.

Upvotes: 2

Related Questions