To have an easy way to manipulation arrays with pointers...
Posted: Sat Nov 05, 2005 12:58 pm
For a one dimension array, an easy way exists, saw here:
viewtopic.php?t=15366
But nothing for multi-dimension arrays?!
Also, why no having something likes this:
Even arrays are global elements, a procedure can need to manipulate a memory area given by an array without knowing the name but just the start point and the dimensions ( i, j, k …)
Ok, it is possible to implement a procedure as:
But, it is a bit complicate no? 
Moreover, we need:
- to implement as much procedure than an array has dimensions. (here the example works until two dimensions)
- an intermediary structure (structure “array” here) to keep array info whereas PureBasic compilo knows already that.
Thus… You want that I become crazy?
viewtopic.php?t=15366
But nothing for multi-dimension arrays?!
Also, why no having something likes this:
Code: Select all
Dim MyArray(10,10)
*a.long = @MyArray
with *a[i][j]\l equivalent to MyArray(i,j)
Ok, it is possible to implement a procedure as:
Code: Select all
Structure array
Adrss.l
NbColumn.l
ElementSize.l
EndStructure
Procedure.l Array(*array.array, i, j)
ProcedureReturn *array\Adrss + ((*array\NbColumn+1) * i + j ) * *array\ElementSize
EndProcedure
Dim MyArray1.f(2)
Dim MyArray2.l(2,2)
Restore val
For i = 0 To 2
Read MyArray1(i)
Next
For i = 0 To 2
For j = 0 To 2
Read MyArray2(i, j)
Next
Next
MyArray1Data.array
MyArray1Data\Adrss = @MyArray1()
MyArray1Data\NbColumn = 0
MyArray1Data\ElementSize = SizeOf(FLOAT)
MyArray2Data.array
MyArray2Data\Adrss = @MyArray2()
MyArray2Data\NbColumn = 2
MyArray2Data\ElementSize = SizeOf(LONG)
*val1.FLOAT= Array(@MyArray1Data, 0, 0)
Debug *val1\f
*val1= Array(@MyArray1Data, 1, 0)
Debug *val1\f
*val1= Array(@MyArray1Data, 2, 0)
Debug *val1\f
*val2.LONG= Array(@MyArray2Data, 1, 0)
Debug *val2\l
*val2= Array(@MyArray2Data, 1, 1)
Debug *val2\l
*val2= Array(@MyArray2Data, 2, 0)
Debug *val2\l
DataSection
val:
Data.f 10.5,20.5,30.5
Data.l 1,2,3
Data.l 4,5,6
Data.l 7,8,9
EndDataSection

Moreover, we need:
- to implement as much procedure than an array has dimensions. (here the example works until two dimensions)
- an intermediary structure (structure “array” here) to keep array info whereas PureBasic compilo knows already that.
Thus… You want that I become crazy?
