Sign in to follow this  

which is quicker, libs or dlls?

This topic is 4815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Quote:
Original post by CodeMunkie
Since you have determined that this is your bottleneck, it should be just a matter of trying both and profiling the results. Let us know how it turns out.


I have no bottleneck. If you look I said I was just wondering, so then I will know for future reference.

Share this post


Link to post
Share on other sites
Once your application is fully loaded into the memory there is absolutely no speed difference whether you use a static library, a dll or some function from your executable.

Loading may be a little slower, although I doubt it. Windows implements dlls using memory mapped files so it'll need to load two files into the memory instead of one (dll + exe vs. just exe) but that should be negligible.

Share this post


Link to post
Share on other sites
If I remember correctly, the program loader set up a table of pointers (at load time, obviously), by looking up for each entry (as defined at compile time by the .LIB import libraries) the address of the matching function (by name or ordinal) in the DLL. Then each DLL call (which include Win32 API and DX) is made through the function pointer located at a given position in the table (e.g. the function Foo is at offset 0x42 in the table, so calls to Foo are all replaced by indirect calls of the function whose address is at offset 0x42).

This is incidentally, the same mechanism as for *gasp* virtual functions *evil*, except you only have one table for the whole program instead of a table per class.

Share this post


Link to post
Share on other sites
Which takes a few picoseconds less than the other is irrelevant, they are both constant time operations to access the functions and that is really all that matters until you are forced to optimise unacceptably slow code.

Often, the benefits of the slower option outweigh the miniscule speed advantage of the faster one anyway.

If you REALLY want to know just for the sake of knowing, then you can easily profile and find out for yourself, or simply google it.

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
Which takes a few picoseconds less than the other is irrelevant, they are both constant time operations to access the functions and that is really all that matters until you are forced to optimise unacceptably slow code.


It's overly simplistic to suggest that just because two operations are constant-time, it makes them somehow the same performance-wise. Obviously constant time can still be very slow.

Unless you're talking about the time complexity of algorithms that operate on a lot of data, terms such as constant-time and linear time have little meaning. Real-world performance is a far more useful measure in general.

Share this post


Link to post
Share on other sites
I've never had the DLL interface be a bottleneck for my code. If you're worried about it, organize your code so that you don't call DLL functions from client code millions of times per second.

Share this post


Link to post
Share on other sites
Quote:
Original post by benjamin bunny
Quote:
Original post by iMalc
Which takes a few picoseconds less than the other is irrelevant, they are both constant time operations to access the functions and that is really all that matters until you are forced to optimise unacceptably slow code.


It's overly simplistic to suggest that just because two operations are constant-time, it makes them somehow the same performance-wise. Obviously constant time can still be very slow.

Unless you're talking about the time complexity of algorithms that operate on a lot of data, terms such as constant-time and linear time have little meaning. Real-world performance is a far more useful measure in general.
Yeah you're correct, and I know all that. But I mean, a call to a dll shouldn't ever be something that's called often enough for it to make a difference, because code that has that strong a cohesion should be in the same module.
Code in a DLL, vs not in a DLL should instead be a speration point between modules, purely by design.

So you see it really isn't an issue unless your design is flawed, in which case fixing the higher level design issue takes priority.

Sneftel says it perfectly.

Share this post


Link to post
Share on other sites
Painting with a broad brush here :)
One example of where DLL indirect call overhead hurts is rand() (DLL CRT).
I vaguely remember needing lots of random numbers for creating a large terrain (8k x 8k), and the same code statically linked was significantly faster.
(yes yes, Mersenne twister and all)

Share this post


Link to post
Share on other sites

This topic is 4815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this