03-04-2026, 10:39 PM
@justsomeguy
I did something similar in my infamous decfloat stuff but the overhead is very high
when dealing with arrays in a type you usually want to access more than one element, possibly all elements so it's way faster to copy the string into a work array and afterwards copy the array back into the string
here's a demo
I did something similar in my infamous decfloat stuff but the overhead is very high
when dealing with arrays in a type you usually want to access more than one element, possibly all elements so it's way faster to copy the string into a work array and afterwards copy the array back into the string
here's a demo
Code: (Select All)
_Title "array-memcpy-offset"
$Console:Only
_Dest _Console
Option _Explicit
Declare CustomType Library
Sub memcpy Alias "memmove" (ByVal dest As _Offset, ByVal source As _Offset, ByVal bytes As Long)
End Declare
Const amax = 1000
Const smax = 8 * (1 + amax)
Dim As Double sum, x(amax), y(amax)
Dim As String * smax sx
Dim As String * smax sy
Dim As _Offset sxo, axo, syo, ayo
Dim As Long i
sxo = _Offset(sx)
axo = _Offset(x(0))
syo = _Offset(sy)
ayo = _Offset(y(0))
sum = 0
For i = 0 To amax
x(i) = i
sum = sum + i
Next
Print sum
memcpy sxo, axo, smax 'copy x array into the string sx
sy = sx ' copy the string sx to string sy
memcpy ayo, syo, smax 'copy content of string sy to array y
sum = 0
For i = 0 To amax
sum = sum + y(i)
Next
Print sum

