08-23-2022, 11:49 AM
I agree with you on the need for array's in udt's, my only complaints with the _mem approach is that it looks messy setting and getting the values and the need to cleanup afterwards
I had a different idea, use a member of string * number_of_elements * size_of_element and copy from that string member to a temporary array when operations on the member elements are needed and copy the array back to the string member, I hope that you won't mind me posting an example of my idea
the drawbacks are the need for temporary arrays and having to copy the udt member to the array and back
I had a different idea, use a member of string * number_of_elements * size_of_element and copy from that string member to a temporary array when operations on the member elements are needed and copy the array back to the string member, I hope that you won't mind me posting an example of my idea
the drawbacks are the need for temporary arrays and having to copy the udt member to the array and back
Code: (Select All)
$Console:Only
_Dest _Console
Declare CustomType Library
Sub memcpy (ByVal dest As _Offset, Byval source As _Offset, Byval bytes As Long)
End Declare
Const max = 20
Const max4 = 4 * (max + 1)
Type foo
m As String * Max4
End Type
Dim As Long i, m
Dim As Long a(max), b(max)
Dim x As foo
Print "populate array a, a(i) = i"
For i = 0 To max
a(i) = i
Next
Print "copy array a to member m of x"
memcpy _Offset(x.m), _Offset(a()), Len(a())
Print "prove that the copy was successful"
For i = 0 To max
m = CVL(Mid$(x.m, 4 * i + 1, 4)) 'this messy way to access the member data is only used to prove that the copy was successful
Print "i = "; i, "x.m["; i; "] = "; m
Next
Print "copy member m of x to array b"
memcpy _Offset(b()), _Offset(x.m), Len(b())
Print "prove that the copy was successful"
For i = 0 To max
Print "i = "; i, "b("; i; ") = "; b(i)
Next