When I pass the result of a function as parameter of a procedure, will it evaluate the result and thereafter only use the result as the parameter of the procedure or will it go through the function again to retrieve the result each time the parameter is used in the procedure?
This may sound confusing so see my example:
Simba Code:
DropArray(ClearTIAFromTIA(OreSearchSlots, gemSlots));
DropArray is a procedure which refers to its parameter in a loop, and ClearTIAFromTIA is a function that returns a TIA (which is passed to DropArray as parameter).
So when the procedure is called, will it:
1. Evaluates ClearTIAFromTIA and retrieve the result
2. Directly use the result thereafter as the parameter
OR
1. Go straight into DropArray
2. Retrieve the result of ClearTIAFromTIA whenever it uses the parameter, resulting in ClearTIAFromTIA being called multiple times.
In most cases it doesn't matter but in this case both the procedure and the function contains loops so it may affect performance. If it is the latter then i'd have to assign result of ClearTIAFromTIA to another variable.
Also would my ClearTIAfromTIA cause memory leak? (Not sure if resetting the result works?) I don't want to use wrapper since if for the case above, the formal is true i won't have to declare an extra variable every time i call the function.
Simba Code:
function ClearTIAFromTIA(const TIA, ClearTIA: TIntegerArray): TIntegerArray;
var
l, l2, i, i2: Integer;
begin
SetLength(Result, 0); //resets the result to prevent leak
l:= High(TIA);
l2:= High(ClearTIA);
for i:=0 to l do
begin
for i2:=0 to l2 do
begin
if (ClearTIA[i2] = TIA[i]) then
Break;
if (i2 = l2) then
begin
SetLength(Result, Length(Result) + 1);
Result[High(Result)]:= TIA[i];
end;
end;
end;
end;