DLLs and speed...

Started by
6 comments, last by stani 23 years, 4 months ago
Hi all. This was just a spontaneous question that I had and could not answer. Let''s assume I build a library of time-critical functions (a 3D engine, for example), do I loose speed if I access them from a DLL instead of having them compiled directly into the engine? If so, what is the overhead, meaning, how much am i loosing?
Advertisement
You might have your program load a little slower, and close a little slower, but your run time should be about the same (not enough difference to notice), any difference would probably be a coincidence or a problem with your DLL code...


http://www.gdarchive.net/druidgames/
For standard usage of a DLL, you''d probably only lose about 1 clock cycle on each non-local DLL call. That is a call from within the DLL to another function in that DLL would have no additional overhead. Calls to functions in delayloaded DLLs can be much, much more expensive.
just a thought. but, under protected mode programming concepts. calling a function from a DLL would mean calling a function in a different code segment, thus requiring a far call. functions all in the same code base, mean linked by the linker and not by the windows loader would be a near call. a far call is definitely slower than a near call { however minute, it''s still slower } this a DLL function calls would be slower. i haven''t looked a the disassembly of DLL calls { i will though } to see if this is the case.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
quote:Original post by jenova

just a thought. but, under protected mode programming concepts. calling a function from a DLL would mean calling a function in a different code segment, thus requiring a far call.


Hmm, your information is kind of... outdated.
All this NEAR-FAR crap was in the Win16.
Win32 uses flat address space, so all of the jump/call-s are NEAR.
(well, there are some exceptions in the kernel & drivers...)

P.S.
calling a function from a DLL is a little bit slower - it''s an indirect call (by pointer in a memory).
thnx a lot to everybody.

so, how is it done in the industry? do the ''big guys'' use dlls for such stuff or do they compile it into the executable?
quote:Original post by stani
so, how is it done in the industry? do the ''big guys'' use dlls for such stuff or do they compile it into the executable?


If it is really time critical, then shouldn''t it be inlined?

A dll is used so that you do not need to recompile the program when you need to do updates to the lib.(if your interfaces stay constant)

If it is something then won''t be changed, then better not put it in dll cause too many dlls will slow your loading code by a lot!.
If you rebase the DLLs, then loading time isn''t affected all that much.

And no a time critical tight loop shouldn''t contain a DLL call, but there''s no reason you can''t put that tight loop inside a DLL function.

This topic is closed to new replies.

Advertisement