06-04-2025, 09:15 AM
Mem works with arrays; there's no problem with that. The only issue is the entire array is pointed to by the mem block, so if you want to use individual elements yourself, then you have to calcaulate their position manually and fetch only what you need from that segment of the entire array mem block.
For example
DIM a(10), m AS _MEM
m = _MEM(a()) '<-- to point to the array a() and not some variable a
_MEMPUT m, m.OFFSET, 12.34 AS SINGLE
_MEMPUT m, m.OFFSET + 8, 98.76 AS SINGLE
FOR I = 0 TO 10
PRINT a(i)
NEXT
The above will print:
12.34
0
98.76
(and several more 0s)
Notice how I moved my pointer over 8 spaces to put the data into a(2)? If you're looking to address individual elements of your array, you have to track their position manually like above.
For example
DIM a(10), m AS _MEM
m = _MEM(a()) '<-- to point to the array a() and not some variable a
_MEMPUT m, m.OFFSET, 12.34 AS SINGLE
_MEMPUT m, m.OFFSET + 8, 98.76 AS SINGLE
FOR I = 0 TO 10
PRINT a(i)
NEXT
The above will print:
12.34
0
98.76
(and several more 0s)
Notice how I moved my pointer over 8 spaces to put the data into a(2)? If you're looking to address individual elements of your array, you have to track their position manually like above.
