Api Declarations - Public vs Private
Hi all,
I've got a strange question:
How does private API declaration in a module (not class module) differ than public ones in terms of performance? Would 20 private declarations of CopyMemory across 20 different modules cause any overhead than just having 1 public declaration of CopyMemory?
Does anyone have any insight into this? I'm mainly asking this out of curiosity but also to determine what would be a best programming practice as currently I'm privately declaring all API calls in a module/class that use them.
I tried using search to find any existing topic but its throwing an error atm :).
Re: Api Declarations - Public vs Private
In terms of performance I'm almost certain that there is no difference at all.
In terms of best practice I would say that Private declarations are better, because not only does it allow for variations if apt (some API's can take slightly different parameters for different uses), but it also means that the code is more self-contained and thus more re-usable.
Re: Api Declarations - Public vs Private
I don't know the answer myself, though I lean toward Private myself for the reasons already given.
I'm sure the library is only loaded once, I doubt it is possible to load it twice. The question is really how much overhead there may be in the Declare data structure VB uses.
I know there is less overhead overall using typelibs instead of Declare though. No runtime data structure, less actual calling overhead. It just isn't enough normally to be worth creating the custom typelibs required.
Re: Api Declarations - Public vs Private
Well if its Private then it can only be called in that Form/Module if its Public then it can be called from any Form/Module. Do a test and try it?
In older VB3, VB4 apps they didn't use Private or Public it was just Declare and that acted like Public.
Re: Api Declarations - Public vs Private
Well if its Private then it can only be called in that Form/Module
I think that's the idea.