As far as I know, when passing an array to a procedure / function, its address is passed, but not the array itself.
type TBigData = array of UInt64; procedure Add_pr(Var arr_to: TBigData; Const arr_from: TBigData); --суммирует два массива, результат пишет в первый begin arr_to[i] := arr_to[i] + arr_from[i];//Код пропущен, просто суммирование двух массивов в первый end; function Add_fu(Const arr_to, arr_from: TBigData): TBigData; --суммирует два массива, результат пишет в третий (fun.Result) begin Result[i] := arr_to[i] + arr_from[i];//Код пропущен, просто суммирование двух массивов в третий end; Sometimes you need to summarize into one of two arrays that are addends, sometimes you need to create a new one (the third one) and add a sum there.
The speed of the algorithm is important, the question is about the code, I want to not follow the two versions of the function procedure (there are the same "pairs" in division, multiplication, subtraction, etc., all for the same work inside two arrays, or to add the result to third).
How to combine the code percent / function without losing the speed of the algorithm? Sort of
function Add_fu(Var arr_to: TBigData; Const arr_from: TBigData): TBigData; begin Result[i] := arr_to[i] + arr_from[i]; end; When calling, if you want to work create a third array:
arr3 := Add_fu(arr1,arr2); If you need to add the sum to the first array of the item, the third array-result is not needed:
arr1 := Add_fu(arr1,arr2); Is it possible to do without a little blood without losing the speed of the algorithm, with a minimum of changes. Will there be any problems with such a call ( arr1 := Add_fu(arr1,arr2) ) and creating copies and other brakes and errors? It seems that inside the Result function, arr_to is just a link to an address, and depending on the function call, they can be the same or different arrays, but who knows how this is implemented in Delphi 10.2?
Delphi .Net?? - MBo