Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a DLL slower than a static link?

Tags:

c++

c

I made a GUI library for games. My test demo runs at 60 fps. When I run this demo with the static version of my library it takes 2-3% cpu in taskmanager. When I use the DLL version it uses around 13-15%. Is that normal? Is so, how could I optimize it? I already ask it to use /O2 for the most function inlining.

like image 398
jmasterx Avatar asked Nov 10 '10 22:11

jmasterx


People also ask

Is static linking faster?

Static linking is the result of the linker copying all library routines used in the program into the executable image. This may require more disk space and memory than dynamic linking, but is both faster and more portable, since it does not require the presence of the library on the system where it is run.

Can a DLL be statically linked?

The client executable calls the exported functions of the DLL the same way as if the functions were statically linked and contained within the executable. Implicit linking is sometimes referred to as static load or load-time dynamic linking.

Is DLL static?

LIB vs DLL LIB is a static library where functions and procedures can be placed and called as the application is being compiled. A DLL or Dynamic Link Library does the same function but is dynamic in a sense that the application can call these libraries during run-time and not during the compilation.

Can a DLL link to static library?

The DLL can link to the same MFC static link libraries used by applications. There is no longer a separate version of the static link libraries for DLLs.


1 Answers

Do not start your performance timer until the DLL has had opportunity to execute its functionality one time. This gives it time to load into memory. Then start the timer and check performance. It should then basically match that of the static lib.

Also keep in mind that the load-location of the DLL can greatly affect how quickly it loads. The default base addres for DLLs is 0x400000. If you already have some other DLL in that location, then the load process must perform an expensive re-addressing step which will throw off your timing even more.

If you have such a conflict, just choose a different base address in Visual Studio.

like image 189
Brent Arias Avatar answered Sep 28 '22 06:09

Brent Arias