ByRef and ByVal Performance

When passing variables to procedures that are either in the same project or that are methods of an in-process ActiveX component, ByRef is much faster than ByVal. This is because the memory reference gives the called procedure almost instantaneous access to the variable's value.

However, when passing variables to a method in an out-of-process server, ByVal has the performance advantage. This is because a procedure in a different process can't use the reference supplied by ByRef. Since they don't share memory, the called procedure has to obtain a copy of the variable's value. But since parame-

Passing Parameters 51

ters are usually passed by reference to permit called routines to change their value, the value of the ByRef argument is copied back to the calling procedure, and the original variable is updated with this value.

Was this article helpful?

0 0

Post a comment