Results 1 to 5 of 5

Thread: Api Declarations - Public vs Private

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    5

    Smile 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 .

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    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.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.

  4. #4
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,238

    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.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width