Thread: DLL function by ordinal v.s. by name

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    DLL function by ordinal v.s. by name

    Hello everyone,


    1. Generally speaking using GetProcAddress through ordinal is faster than through name, right?

    2. Why?


    thanks in advance,
    George

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Quote Originally Posted by George2 View Post
    Hello everyone,


    1. Generally speaking using GetProcAddress through ordinal is faster than through name, right?

    2. Why?


    thanks in advance,
    George
    Probably because using the ordinal number eliminates an intermediate step of doing a binary search on the names table.

    For instance, using a function name, a binary search of the sorted names table would be done until it found the function name. Let's assume that the function name is the 4th entry in the names table. Now we have to read the 4th entry value from our ordinal table which is our ordinal value. Next, the ordinal value is used as an index into the address table to find the relative virtual address of the function which has to be converted to the actual address.

    Now contrast this to using an ordinal number which would only require going directly to the address table. Thus eliminating the binary search.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    But you (hopefully) only do this ONCE per function in the early part of the program - so it's unlikely that you will see any difference in the execution time of a real application.

    If you have hundreds or thousands of DLL references that you look up by name or ordinal, then you are probably doing something wrong, particularly if you have to do it over and over again.

    If that is really what you are worried about, then perhaps working out a way to have a single entry point that returns a struct/array of function pointers is the right way to do things. (Or, if it's C++, return a pointer to a class).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks BobS0327,


    Quote Originally Posted by BobS0327 View Post
    Probably because using the ordinal number eliminates an intermediate step of doing a binary search on the names table.

    For instance, using a function name, a binary search of the sorted names table would be done until it found the function name. Let's assume that the function name is the 4th entry in the names table. Now we have to read the 4th entry value from our ordinal table which is our ordinal value. Next, the ordinal value is used as an index into the address table to find the relative virtual address of the function which has to be converted to the actual address.

    Now contrast this to using an ordinal number which would only require going directly to the address table. Thus eliminating the binary search.
    Your reply is great!! My question is answered.


    Thanks for your advice, Mats!


    Quote Originally Posted by matsp View Post
    But you (hopefully) only do this ONCE per function in the early part of the program - so it's unlikely that you will see any difference in the execution time of a real application.

    If you have hundreds or thousands of DLL references that you look up by name or ordinal, then you are probably doing something wrong, particularly if you have to do it over and over again.

    If that is really what you are worried about, then perhaps working out a way to have a single entry point that returns a struct/array of function pointers is the right way to do things. (Or, if it's C++, return a pointer to a class).

    --
    Mats

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  4. Problem in exporting static function in win32 dll
    By dattaforit in forum Windows Programming
    Replies: 4
    Last Post: 12-04-2006, 12:03 PM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM