Sign in to follow this  
Followers 0
GrahamS

Parameter Efficiency

5 posts in this topic

I am concerned about the efficiency of passing large data structures as parameters to functions. Am I right in assuming that passing a parameter by reference (i.e. using the ByRef keyword) will not perform a copy? If the parameter is passed without the ByRef keyword is a copy performed?

Thanks in anticipation


GrahamS

Share this post


Link to post
Share on other sites



ByRef uses the original variable, no copy is performed. Otherwise, a local (to the function) copy is created for the scope of the function and is destroyed when the function exits.

Share this post


Link to post
Share on other sites

Thanks for the quick reply!


GrahamS

Share this post


Link to post
Share on other sites

Unless you have a good reason not to, always pass arrays by reference - the performance difference is massive (hence why not many languages allow you to pass arrays any other way)

Share this post


Link to post
Share on other sites

That's why I wanted confirmation about my assumption.

Would it not be a good idea to add this to the help file?

BTW I once was called in to troubleshoot a hard real time project, written in C, that had major performance problems. They were passing 1400 byte messages by value, up to 50 times per message! The fix gained an order of magnitude improvement.


GrahamS

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0