Here is version 2 of DIRTYCALL with a comparison in time to using the
normal DLL calling technique through the stack. The times show that
DIRTYCALL is more than twice as fast, even though it has to manually
dereference the addresses and load 4 global variables with the
results.
The speed difference is due to DIRTYCALL having no stack overhead, even
though it manually converts the values.
Regards,
[email protected]
[This message has been edited by Steve Hutchesson (edited February 09, 2001).]
normal DLL calling technique through the stack. The times show that
DIRTYCALL is more than twice as fast, even though it has to manually
dereference the addresses and load 4 global variables with the
results.
The speed difference is due to DIRTYCALL having no stack overhead, even
though it manually converts the values.
Regards,
[email protected]
Code:
The calling code. Case 51 TheProc& = PassStruct Rct.nLeft = 1 Rct.nTop = 2 Rct.nRight = 3 Rct.nBottom = 4 tc& = getTickCount() cntr& = 100000000 lbl1: ! lea eax, Rct ; load EAX with address of structure RECT ! call TheProc& ! dec cntr& ! jnz lbl1 tc1& = GetTickCount() - tc& MessageBox hWin,ByCopy str$(tc1&),"PassStruct", _ %MB_OK or %MB_ICONINFORMATION Case 52 tc& = getTickCount() cntr& = 100000000 lbl2: NormalCall 1,2,3,4 ! dec cntr& ! jnz lbl2 tc1& = GetTickCount() - tc& MessageBox hWin,ByCopy str$(tc1&),"NormalCall", _ %MB_OK or %MB_ICONINFORMATION The two DLL functions for comparison. '########################################################################## FUNCTION PassStruct ALIAS "PassStruct" () EXPORT as LONG ! jmp over_it ' ---------------------------- ' struct address in EAX ' ---------------------------- LandHere: GLOBAL var1 as LONG GLOBAL var2 as LONG GLOBAL var3 as LONG GLOBAL var4 as LONG GLOBAL retv as LONG ! mov edx, [eax] ! mov var1, edx ! mov edx, [eax+4] ! mov var2, edx ! mov edx, [eax+8] ! mov var3, edx ! mov edx, [eax+12] ! mov var4, edx ' ------------------------------------ ' commented out to test calling speed ' ------------------------------------ ' retv = (var1 * var2) ^ (var3 + var4) ' ! mov eax, retv ! ret ' ---------------------------- over_it: FUNCTION = CodePtr(LandHere) END FUNCTION ' ######################################################################### FUNCTION NormalCall ALIAS "NormalCall" (ByVal a as LONG, _ ByVal b as LONG, _ ByVal c as LONG, _ ByVal d as LONG) EXPORT as LONG ' ------------------------------------- ' empty function to test calling speed ' ------------------------------------- FUNCTION = 0 END FUNCTION ' #########################################################################
Comment