03-10-2005, 10:09 AM
I was trying to rebuild the gl program I made using pointers and I ran into trouble. I made this for a small example... Can anyone show me what I'm doing wrong? I'm not able to access those Callocated arrays from main. :???:
Code:
Type Vector3DType
X as Single
Y as Single
Z as Single
End Type
Type Main_Type
Indices as Integer
End Type
Type Alloc_Type
Arr(3) as Vector3DType
End Type
Declare Sub Make_Vals( mArray as Main_Type, aArray as Alloc_Type ptr)
Declare Sub Print_Vals( mArray as Main_Type, aArray as Alloc_Type ptr )
Declare Sub Kill_Vals(aArray as Alloc_Type ptr )
Dim Main_Array(1 to 10) as Main_Type
Dim Alloc_Array(1 to 10) as Alloc_Type Ptr
Make_Vals Main_Array(1), Alloc_Array(1)
Print_Vals Main_Array(1), Alloc_Array(1)
sleep 500
CLS
Dim aArray as Alloc_Type ptr
aArray = @Alloc_Array(1)
For i = 1 to Main_Array(1).Indices
Print aArray[i].arr(1).X
Print aArray[i].arr(1).Y
Print aArray[i].arr(1).Z
Next
Sleep 500
Kill_Vals Alloc_Array(1)
Sub Make_Vals( mArray as Main_Type, aArray as Alloc_Type ptr )
mArray.Indices = 100
aArray = Callocate(mArray.Indices * Len(Alloc_Type))
For i = 1 to mArray.Indices
aArray[i].arr(1).X = rnd*3
aArray[i].arr(1).Y = rnd*3
aArray[i].arr(1).Z = rnd*3
Next
End Sub
Sub Print_Vals( mArray as Main_Type, aArray as Alloc_Type ptr )
For i = 1 to mArray.Indices
Print aArray[i].arr(1).X
Print aArray[i].arr(1).Y
Print aArray[i].arr(1).Z
Next
End Sub
Sub Kill_Vals(aArray as Alloc_Type ptr )
Deallocate(aArray)
End Sub