In that tip you are internally swapping pointers but in the tip there is not used the pointers in a syntactic way for PB, but just using the reference of the base of the array.
However, there is a bug which is critical as i see in the 5.20 version:
When there is swapped two pointers (native vartype is integer '.i' ) in a syntaxically way, i.e. using '@' or '*' as prefix, it should work.
... but it does not.
Next tip display (under PB5.20):
'Swap' only works with 2 elements of the same native type, (not structured)
But the type is native as it is just pointers.
Code: Select all
Dim tableau1(5):Dim tableau2(5)
For i=0 To 5
tableau1(i)=i
tableau2(i)=i+10
Next i
Swap @tableau1(),@tableau2() ; <- no works to PB520 !!
For i=0 To 5
Debug tableau1(i)
Debug tableau2(i)
Next i
Sorry to say that it is dissapointing to me and to others when a newer PB version introduces some bug that didn't exist in before versions. Thanks!
@kernadec:
You can use this functional alternative for x86 32bit (if need it for 64bit just modify the macro accordingly or ask me for it):
Code: Select all
Macro mySwap(a,b); 32bit x86
!mov eax,dword[a_#a]
!xchg eax,dword[a_#b]
!mov dword[a_#a],eax
EndMacro
Dim tableau1(5):Dim tableau2(5)
For i=0 To 5
tableau1(i)=i
tableau2(i)=i+10
Next i
; Swap tableau1(),tableau2()
mySwap(tableau1,tableau2)
For i=0 To 5
Debug tableau1(i)
Debug tableau2(i)
Next i