mem arrays
#2
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
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
Reply


Messages In This Thread
mem arrays - by James D Jarvis - 08-23-2022, 04:45 AM
RE: mem arrays - by Jack - 08-23-2022, 11:49 AM
RE: mem arrays - by James D Jarvis - 08-23-2022, 12:43 PM
RE: mem arrays - by Jack - 08-23-2022, 12:50 PM
RE: mem arrays - by James D Jarvis - 08-23-2022, 02:08 PM
RE: mem arrays - by SpriggsySpriggs - 08-31-2022, 01:14 PM
RE: mem arrays - by mdijkens - 08-31-2022, 02:37 PM



Users browsing this thread: 3 Guest(s)