Strange hang

Peter Haworth pete at lcsql.com
Tue Jan 15 12:23:37 EST 2013


Alex is right, as usual. I always forget about the memory saving aspects of
referenced parms.

I'm remembering that I do have a couple of functions that use referenced
parameters. They manipulate the referenced data in a way that may or may
not succeed, and return true or false accordingly.

Pete
lcSQL Software
On Jan 15, 2013 4:34 AM, "Alex Tweedly" <alex at tweedly.net> wrote:

> On 15/01/2013 06:29, Peter Haworth wrote:
>
>> I believe what you cannot do is pass an array element by reference. So
>> your
>> faddnum function cannot be declared as:
>>
>> function faddnum @pnum
>>
>
> That's right.
>
>> Not that you would want to do that in a function but you might be tempted
>> to make it a command defined that way.
>>
> I'm not so sure that you wouldn't want to do it with a function :-)
>
> There are two reasons to make a parameter be "passed by reference".
>
> 1. to allow it to be modified within the function/handler
> 2. to save the cost of copying the variable (e.g. if it's a very large
> array or string).
>
> Either of these could apply to functions just as easily as to handlers.
> It's common "good practice" to avoid side-effects (i.e. modification of
> by-ref parameters) in functions - but if the main purpose is to modify the
> parameter, and the returned value from the function is just a simple way to
> indicate success/failure, then it's arguably a very reasonable coding
> practice.
>
> And the cost saving of not copying can be significant - though ONLY IF the
> variable content may be VERY large (i.e. Gbytes or many tens of Mbytes of
> string or nested array), and/or the function may be called very often.
>
> -- Alex.
>
>
>
> ______________________________**_________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/**mailman/listinfo/use-livecode<http://lists.runrev.com/mailman/listinfo/use-livecode>
>



More information about the use-livecode mailing list