Page 1 of 1

Prototype or Import, what's better (and faster)?

Posted: Sat Jul 14, 2007 9:23 am
by Max
Hi,
Somebody can explain me what construction is better and faster, for use dlls?:

Code: Select all

Prototype.l sql_init(mysql.l)
nlib = OpenLibrary(#PB_Any, "libmysql.lib")
mysql_init.sql_init=GetFunction(nlib, "mysql_init")
OR:

Code: Select all

Import "libmysql.lib"
mysql_init.l(*mysql.l)
I know the "theoretical"difference between them, but I dont know the "practical" difference between both approachs.

thanks @all

Posted: Sat Jul 14, 2007 9:30 am
by DarkDragon
Prototypes are dynamic, imports are static. For example in OpenGL I use the following routine to get the Shader functions:

Code: Select all

Prototype.l glDeleteObjectARB_(obj.l)
Prototype.l glGetHandleARB_(pname.l)
; ...

Global glDeleteObject_.glDeleteObjectARB_
Global glGetHandle_.glGetHandleARB_
; ...

Procedure InitGLSLShader()
  glDeleteObject_ = wglGetProcAddress_("glDeleteObjectARB")
  glGetHandle_ = wglGetProcAddress_("glGetHandleARB")
  ; ...
EndProcedure
But you need static (Imports) because you are able to bind them in the static way.

Posted: Sat Jul 14, 2007 10:12 am
by Max
thanks, DarkDragon
Now, I know the difference, and I know that I need static imports.
But, there is some advantage in doing it on a way or another one?
I've read somewhere on this forum that Prototypes are faster, is 't true?

Posted: Sat Jul 14, 2007 5:00 pm
by ts-soft
Prototype and Import the same. Only the binding to a DLL is another. Import
makes a static Binding. It's faster than dynamic Binding, but if the DLL is
Missing, Windows gives the Error. Your Programm can't solve the Problem.

Posted: Sat Jul 14, 2007 5:30 pm
by Max
Thanks for the explanation.
Now it's clear for me. I will continue using IMPORT.

Posted: Sat Jul 14, 2007 5:46 pm
by freak
Linking an import library is not faster than calling the dll functions directly, because
the import library also does an indirect call to the dll function. Basically it is
just doing the pointer work for you, but the dll is still loaded and called dynamically.

Posted: Sat Jul 14, 2007 6:13 pm
by Trond
Loading would be faster with Import, not calling.