QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Qwerkey on October 01, 2019, 03:53:20 pm

Title: An Array of _MEM Objects?
Post by: Qwerkey on October 01, 2019, 03:53:20 pm
Is it possible to have an array of _MEM objects (This is not an array sent to a _MEM block)?

I have an index which can vary from 4 to 10 and for each index I want to address a particular and distinct _MEM object.  Is it possible to do this without doing a SELECT CASE on the index and pointing to the appropriate _MEM object?

I've tried the following code and it works OK, so unless informed otherwise, I'll cary on along these lines.
Code: QB64: [Select]
  1. DIM M(10) AS _MEM
  2.  
  3. M(4) = _MEMNEW(4)
  4. M(5) = _MEMNEW(5)
  5. M(6) = _MEMNEW(6)
  6. 'Et cetera
  7.  
  8. FOR N%% = 4 TO 6
  9.     _MEMPUT M(N%%), M(N%%).OFFSET, N%% AS _UNSIGNED LONG
  10. NEXT N%%
Title: Re: An Array of _MEM Objects?
Post by: SMcNeill on October 01, 2019, 04:31:31 pm
MEM as an array works fine. 

Code: [Select]
DIM B AS _BYTE, I AS INTEGER, L AS LONG
DIM M(2) AS _MEM
M(0) = _MEM(B)
M(1) = _MEM(I)
M(2) = _MEM(L)

With the above, we have a MEM Array, which points to all 3 of our other variables.