Author Topic: An Array of _MEM Objects?  (Read 2743 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
An Array of _MEM Objects?
« 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%%

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: An Array of _MEM Objects?
« Reply #1 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. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!