Swap arrays
Posted: Wed Jun 23, 2010 3:22 pm
I wish that Swap could be used with arrays, to simply swap the names/pointers to the array.
Code: Select all
Dim Test1(5)
Dim Test2(5)
For k = 1 To 5
Test1(k) = k
Next
For k = 1 To 5
Test2(k) = k + 5
Next
Debug "Before Swap:"
Debug "Test1:"
For k = 1 To 5
Debug Test1(k)
Next
Debug #CRLF$
Debug "Test2:"
For k = 1 To 5
Debug Test2(k)
Next
Swap @Test1(), @Test2()
Debug #CRLF$
Debug "After Swap:"
Debug "Test1:"
For k = 1 To 5
Debug Test1(k)
Next
Debug #CRLF$
Debug "Test2:"
For k = 1 To 5
Debug Test2(k)
Next
Code: Select all
Procedure.l getMiscData()
*myPtr = AllocateMemory(12)
; Set asside enough memory for three long integers (4 bytes ea.)
PokeL(*myPtr, 123)
PokeL(*myPtr+4, 456)
PokeL(*myPtr+8, 789)
ProcedureReturn *myPtr
EndProcedure
*thisPtr = getMiscData()
Dim myArray.l(MemorySize(*thisPtr)/4) ; same as Dim myArray.l(3)
myArray() = *thisPtr
For k = 0 To 2
Debug myArray(k)
Next
FreeMemory(*thisPtr)