3
In ADVPL what difference to make:
aArray1 := {"A", "B", "C"}
aArray2 := aArray1
or
aArray2 := aClone(aArray1)
3
In ADVPL what difference to make:
aArray1 := {"A", "B", "C"}
aArray2 := aArray1
or
aArray2 := aClone(aArray1)
5
The first assignment only references memory, making the two arrays point to the same memory position. So we have:
Conout(aArray1[2]) //Imprime B
aArray2[2] := "R" //Altera o segundo array faz a alteração no primeiro
Conout('aArray1[2]) //Imprime R
In case 2 the array is copied:
aArray2 := aClone(aArray1)
Conout(aArray1[2]) //Imprime B
aArray2[2] := "R" //Altera o segundo array não faz a alteração no primeiro
Conout('aArray1[2]) //Imprime B
Obs. Whenever we use an array, especially when we clone them with aClone, we must at the end of the use clean the memory space used with the aSize function.
aArray2 := aSize(array2,0) //Zera o uso da memoria.
0
When making a simple assignment of an array using the operator ':=' one variable will reference the memory address of the other, using the aClone function() (http://tdn.totvs.com/display/tec/AClone) a real copy of the array will be assigned to the variable.
Browser other questions tagged array advpl
You are not signed in. Login or sign up in order to post.