Sign in to follow this  

question about dll performance being compared to a virtual function lookup

This topic is 4676 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

I've noticed several times now that people are saying using a function/class from a dll has about the same performance as calling virtual function. What makes you say this? I view it just the same as though I had written a static library. The linker will take care of resolving the reference to the function in my dll if I statically bind my dll to the executable or when I call GetProcAddress I'm going to hold onto the address of the function in memory until I exit my program. In both cases it seems as though it is just like resolving a normal function reference. I have tried to google for it but I'm not putting in very good keywords and am getting lots of noise. I would appreciate any insight you all have on this. Thanks!

Share this post


Link to post
Share on other sites
When you link to a DLL, the compiler has a table of exports that it uses. when your app starts up, Windows loads the DLL and hooks the export table to the locations of the functions in the DLL.
So, when you call a function in the DLL from within your exe, the compiler inserts code to do this:
  • Goto lookup table entry for function x (same as looking at a virtual function table)
  • Call the code located at the pointer in the lookup table (call it like a function pointer)

    The reason the compiler can't jump straight into the DLL code, is it doesn't know what location in memory it'll be at. Usually, DLLs load at 0x10000000 (or 0x01000000, I don't remember which exactly), but if there are two DLLs loaded, they could fight for that space. In that case, one DLL ends up getting relocated (to e.g. 0x0f000000), which means that the exe would choke if it assumed the DLL was at 0x10000000.

    Share this post


    Link to post
    Share on other sites
    All right that makes sense. I understand about rebasing dll's and the export table makes sense. Thanks for the response. Thought I was going to have to put "Noob who wants to make MMORPG that kicks butt, no experience" in my title to get a response.

    Share this post


    Link to post
    Share on other sites

    This topic is 4676 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