by reference parameters
Rob Cozens
rcozens at pon.net
Wed Sep 17 05:38:00 EDT 2003
>I was just doing some transcript tests and I can't see a speed
>difference between a handler with regular params vs by-reference
>parameters. Am I a correct that @params aren't used for optimization?
Hi Alex,
I see two uses for referenced parameters, and one involves
optimization (or execution speed).
From my perspective, the speed difference only comes into play when
the arguments are large. For example, the record buffer in SDB is
ALWAYS passed by reference.
A. In theory, an SDB record can be as large as the largest string
Revolution supports. If the buffer is passed by value, it is
duplicated with each call; if passed by address, the original buffer
location is referenced by every handler. If the size of argument
you're passing is measured in megabytes, I don't see how passing by
reference [address] can't help but perform better.
B. In addition, several SDB library handlers may reference the same
buffer during the execution of a single command. I wouldn't want the
overhead of duplicating the buffer for each individual handler.
The other reason for passing by reference is that in some designs it
just makes sense to have the handler update the original variable
directly instead of returning a value that then replaces the original.
--
Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.net/who.htm
"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."
from "The Triple Foole" by John Donne (1572-1631)
More information about the use-livecode
mailing list