dcsimg
Results 1 to 4 of 4

Thread: ByRef very efficient?

  1. #1

    Thread Starter
    Hyperactive Member capsulecorpjx's Avatar
    Join Date
    May 2005
    Location
    Renton, WA
    Posts
    288

    ByRef very efficient?

    Hey how efficient is ByRef? It's a pointer argument right? So I would say it'd take up a Long (4 bytes)?

    For example,
    say I have a procedure in a module that does work depending on the form specified.
    Below are two versions of this function, do which one is more efficient, or do they perform the same?

    1) Passing the whole Form with ByRef
    Public Sub HandleForm(ByRef frmForm As Form)

    Select Case frmForm.hWnd
    Case frmTest1.hWnd
    ...
    Case frmTest2.hWnd
    ...
    End Select

    End Sub

    2) Passing only the form handle
    Public Sub HandleForm(llFormHWnd As Long)

    Select Case llFormHWnd
    Case frmTest1.hWnd
    ...
    Case frmTest2.hWnd
    ...
    End Select

    End Sub
    "I like to run on treadmills, because at least I know I'm getting nowhere."
    - Me

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: ByRef very efficient?

    Have you tried to benchmark it?

    Something tells me the form handle method is quicker.
    In the ByRef method the function needs to go and get the form's handle and store it in a variable, where in the form handle method the handle is already a variable.
    (someone please correct me if I'm wrong, because I could be)

    I don't think it really makes a big difference.
    Delete it. They just clutter threads anyway.

  3. #3

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: ByRef very efficient?

    ByRef only passes an Address... Hense the name By Reference...

    And in you second example you are passing ByRef also. ByRef is the default if you do not specify ByVal (By Value) - It pushes the actual value on a stack... Meaning you can change the value and the original will not be affected. With ByRef the original will be affected.


    When in doubt, Test it out!!!!
    Last edited by randem; Nov 20th, 2007 at 05:02 PM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width