String parameters
Procedure string parameters differ from numeric parameters in that with strings, the chosen parameter passing convention makes a real performance difference.
Pass strings ByRef
How should you define procedure parameters for calls from within the same project?
ByVal is slow for string parameters. ByVal makes a copy of the string on every call. The good side is that a ByVal parameter is safe to modify: the modifications aren't passed back to the callers.
ByRef is faster because the string doesn't get copied. The drawback is that you have to be careful. If your intention is not to return a value in the ByRef parameter back to the caller, you may not accidentally write to this parameter.
Use ByRef instead of function return value
There's also an optimization trick for returning a string value. Returning a string as the function return value is the normal practice. However, returning a string in a ByRef parameter is faster.
The ByRef trick for return values applies to both functions and Property Get's. Here's the usual (and slower) way:
' Slow:Property Get Name() As String Name = m_sNameEnd Property' Slow:Function Name() As String Name = m_sNameEnd FunctionThis way is faster if you have to make a large number of calls:
' Fast:Sub GetName(ByRef Name_out As String) Name_out = m_sNameEnd Sub