(Calling a function in a dynamically loaded DLL)
Is it slower than calling locally defined function (standard calling convention)???
Posted on 2002-06-01 20:33:07 by __anti_code_
i think exe is loaded this way.

first windows load the exe and dll associated with it , then assign the address of the functions of the dlls in the address tables.

so if you call a function in a dll it done this way.

first jump to the address table . then jump to the function in the dll .

i.e. it is one step more, this if you ignore the time for loading the dlls :)

i don't know what happened if you static linked the dll to the exe . ( in VC their is option to link all used dlls to the exe so your exe work without asking for those dlls ) i don't know how this done in masm .
also i dont know if it contain one more jump or it is the same as local functions , i think it is the same as local functions.
Posted on 2002-06-01 21:04:29 by Sa6ry
__anti_code_,

Once you have the DLL loaded, the start address is called when you call the DLL function so there is no real time lag to worry about.

You can either load the DLL at startup and carry the overhead of it being loaded all the time or load it on demand with LoadLibrary()/GetProcAddress().

There is some information from Microsoft that using an ordinal number is slightly faster than using a name when you do the call but I have not seen any benchmarking to show its any faster.

Regards,

hutch@movsd.com
Posted on 2002-06-01 21:25:22 by hutch--
thank you for your help.
Posted on 2002-06-01 21:34:36 by __anti_code_
Hello Hutch , hope u r fine.

when i debug an exe i found that i first jump to a location within the exe file then the API is called.

isn't this mean their is one more step ? or what ??

i think i miss something .
Posted on 2002-06-01 22:35:50 by Sa6ry
the jump is jumping over any data at the beginning of a program, which is valid for a DLL, too... of course, you can always re-organise your data so that it comes after the code, thus avoiding the jump.
Posted on 2002-06-01 22:52:42 by jademtech
hi Sa6ry

It depends on how the .exe was linked. the linker that comes with masm uses a jump table so calling a function will call the address of the jump wich jumps to the dll function adding another step. There is a way of linking so that the dll function address is called but instead of the jump, I forget the assembler that dose this.
Posted on 2002-06-01 23:57:33 by Kudos
When you call a locally defined function (or a statically linked function), the CALL that is executed uses PC-relative addressing. The location of the function (relative to the caller's code) must be known before loading.

The DLL functions are called using some form of indirection.
The simplest form is to call a statically linked stub (some call it a thunk, but that has a different meaning to me).
    invoke _API@nn,args


_API@nn PROC args
jmp dword ptr [__imp__APIaddr@n] ; this is the stub (or "thunk")
ENDP

__imp__APIaddr@n DWORD 0 ; this is filled in by EXE/DLL loader
The advantage for HLLs is there is no distinction between subroutines from a static library or from a DLL.

The second form eliminates the JMP stub and is supported by some C/C++ compilers.
    ; push args here

call dword ptr [__imp__APIaddr@n]

__imp__APIaddr@n DWORD 0 ; this is filled in by EXE/DLL loader
Check the Intel and AMD docs on timing and think about the effects of caching to get a true picture of how fast or slow this indirection is.
Posted on 2002-06-02 01:00:56 by tenkey