Re: passing data to functions in other units
From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 08/31/04
- Next message: J French: "Re: passing data to functions in other units"
- Previous message: Kris Leech: "passing data to functions in other units"
- In reply to: Kris Leech: "passing data to functions in other units"
- Next in thread: J French: "Re: passing data to functions in other units"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 31 Aug 2004 12:22:50 -0400
"Kris Leech" <krisleech@email.com> wrote in message
news:ch2818$p4h$1@titan.btinternet.com...
> I assume i can either pass the whole variable to the functions (which
> may be slow?) or pass a pointer to the global variable??
No slower than the time it takes you to sort out any bugs that may occur
because of a poorly choosen passing mechanism ;).
> The global variable i have is a static array of bytes.
Check out the "Parameter Semantics" section of the ObjectPascal (Delphi)
Language Reference portion of the help. (If you can't find it, look up
'value parameters' in the help.)
There are three passing mechanisms in Delphi that you should consider. By
value, the default, will copy the passed variable or expression. When
dealing with arrays this can have an impact on performance. But it does let
the routine freely alter the passed values without worrying about any impact
on the rest of the program. By reference, Var, effectively passes the
address of the passed variable. The routine is therefore working with the
passed variable, not a copy. A third mechanism, Const, allows the compiler
to pick the most efficient passing mechanism. The only proviso is that the
routine cannot attempt to alter the parameter.
So, if you are doing something like adding all the values in a vector, Const
would be the most appropriate choice. But if you were inverting a matrix, in
place, Var would be a better choice. And finally, if you had to sort the
array to find the middle value and didn't want to sort the passed array,
by-value would be the most appropriate choice.
- Next message: J French: "Re: passing data to functions in other units"
- Previous message: Kris Leech: "passing data to functions in other units"
- In reply to: Kris Leech: "passing data to functions in other units"
- Next in thread: J French: "Re: passing data to functions in other units"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|