Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arrays inside Types?
#3
@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
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
Reply


Messages In This Thread
Arrays inside Types? - by Ikerkaz - 03-04-2026, 09:44 PM
RE: Arrays inside Types? - by justsomeguy - 03-04-2026, 09:57 PM
RE: Arrays inside Types? - by Jack - 03-04-2026, 10:39 PM
RE: Arrays inside Types? - by bplus - 03-04-2026, 11:45 PM
RE: Arrays inside Types? - by hsiangch_ong - Yesterday, 01:32 AM
RE: Arrays inside Types? - by ahenry3068 - Yesterday, 04:21 PM
RE: Arrays inside Types? - by Jack - Yesterday, 02:14 PM
RE: Arrays inside Types? - by Kernelpanic - Yesterday, 03:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Arrays as UDTs Pete 26 1,188 02-06-2026, 04:31 AM
Last Post: bplus
  Preserving multi-dim arrays Pete 5 411 12-19-2025, 03:17 PM
Last Post: Dimster
  Array out of passing arrays... Pete 2 404 09-22-2025, 08:53 PM
Last Post: ahenry3068
  Methods in types bobalooie 7 1,546 01-30-2025, 08:00 PM
Last Post: Pete
  C++ types > QB64 types: do we have an equivalent QB64PE page? madscijr 5 1,111 06-01-2024, 03:44 AM
Last Post: grymmjack

Forum Jump:


Users browsing this thread: 1 Guest(s)