Author Topic: A _MEM newbie with a question on moving large blocks of data  (Read 3958 times)

0 Members and 1 Guest are viewing this topic.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
A _MEM newbie with a question on moving large blocks of data
« on: December 27, 2019, 07:26:20 am »
I've been finding Steve's youtube tutorial very enlightening, but I'm wondering about how versatile _MEM operations are.

Does one have to move discrete elements (integer, single, etc.) or can one define a block of data and move it a specified distance?

Below is the test code I've been playing with, the user variable is from my vector plotter, and what I'm seeking to do is to move everything from .ap thru .status (37 bytes), exactly 37 bytes down to reside at .op thru .Ostat.

Can I move one 'get' of 37 bytes to one 'put' 37 bytes downward, or do I have to grab each individual element?

I saw a reference to LEN, but nothing showing as an example of syntax. Would treating it as a string of 37 bytes be the way to go?

Code: QB64: [Select]
  1. TYPE unitpoint '                                                relative unit placement
  2.     pX AS _INTEGER64 '                                          X coordinate / mem 0-7
  3.     pY AS _INTEGER64 '                                          Y coordinate / mem 8-15
  4.     pZ AS _INTEGER64 '                                          Z coordinate / mem 16-23
  5.  
  6. TYPE ship '                                                     unit info variable
  7.     id AS _BYTE '                                               unit ID / mem 0
  8.     Nam AS STRING * 10 '                                        unit name / mem 1 - 10
  9.     MaxG AS _BYTE '                                             Maximum thrust ship can use / mem 11
  10.     op AS unitpoint '                                           previous turn x,y,z position op=old position / mem 12-19,20-27,28-35
  11.     OSp AS SINGLE '                                             previous turn velocity / mem 36-39
  12.     OHd AS SINGLE '                                             previous turn heading / mem 40-43
  13.     OIn AS SINGLE '                                             previous turn inclination / mem 44-47
  14.     Ostat AS _BYTE '                                            previous turn status / mem 48
  15.     ap AS unitpoint '                                           Absolute x,y,z position ap=absolute position / mem 49-56,57-64,65-72
  16.     Sp AS SINGLE '                                              coasting velocity / mem 73-76
  17.     Hd AS SINGLE '                                              coasting heading / mem 77-80
  18.     In AS SINGLE '                                              coasting inclination / mem 81-84
  19.     status AS _BYTE '                                           0=destroyed 1=in flight 2=landed / mem 85
  20.     bstat AS _BYTE '                                            type of solution 0=none 1=evade 2=intercept 3=Planetfall / mem 86
  21.     bogey AS _BYTE '                                            target of intercept/evade solution / mem 87
  22.  
  23. DIM sh AS ship
  24.  
  25. sh.ap.pX = 78: sh.ap.pY = 7800: sh.ap.pZ = 78000
  26. PRINT sh.ap.pX, sh.ap.pY, sh.ap.pZ
  27. PRINT sh.op.pX, sh.op.pY, sh.op.pZ
  28. 'DIM x AS _INTEGER64
  29. m = _MEM(sh)
  30. PRINT m.ELEMENTSIZE
  31. _MEMGET m, m.OFFSET + 49, x 'remember to use m.ELEMENTSIZE & DO-LOOP for array shifts
  32. _MEMPUT m, m.OFFSET + 12, x
  33. _MEMGET m, m.OFFSET + 57, x
  34. _MEMPUT m, m.OFFSET + 20, x
  35. _MEMGET m, m.OFFSET + 65, x
  36. _MEMPUT m, m.OFFSET + 28, x
  37. PRINT sh.ap.pX, sh.ap.pY, sh.ap.pZ
  38. PRINT sh.op.pX, sh.op.pY, sh.op.pZ
  39.  

Marked as best answer by OldMoses on December 27, 2019, 02:43:48 am

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A _MEM newbie with a question on moving large blocks of data
« Reply #1 on: December 27, 2019, 07:33:13 am »
_MEMCOPY is what you’re looking for.  https://www.qb64.org/wiki/MEMCOPY

Copy from the old spot, to the new spot, and then use _MEMFILL if you need to blank out the original area.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: A _MEM newbie with a question on moving large blocks of data
« Reply #2 on: December 27, 2019, 07:34:53 am »
UPDATE:

Ah yes! defining a 37 byte string and moving it worked perfectly!

Done in one move.

Code: QB64: [Select]
  1. TYPE unitpoint '                                                relative unit placement
  2.     pX AS _INTEGER64 '                                          X coordinate / mem 0-7
  3.     pY AS _INTEGER64 '                                          Y coordinate / mem 8-15
  4.     pZ AS _INTEGER64 '                                          Z coordinate / mem 16-23
  5.  
  6. TYPE ship '                                                     unit info variable
  7.     id AS _BYTE '                                               unit ID / mem 0
  8.     Nam AS STRING * 10 '                                        unit name / mem 1 - 10
  9.     MaxG AS _BYTE '                                             Maximum thrust ship can use / mem 11
  10.     op AS unitpoint '                                           previous turn x,y,z position op=old position / mem 12-19,20-27,28-35
  11.     OSp AS SINGLE '                                             previous turn velocity / mem 36-39
  12.     OHd AS SINGLE '                                             previous turn heading / mem 40-43
  13.     OIn AS SINGLE '                                             previous turn inclination / mem 44-47
  14.     Ostat AS _BYTE '                                            previous turn status / mem 48
  15.     ap AS unitpoint '                                           Absolute x,y,z position ap=absolute position / mem 49-56,57-64,65-72
  16.     Sp AS SINGLE '                                              coasting velocity / mem 73-76
  17.     Hd AS SINGLE '                                              coasting heading / mem 77-80
  18.     In AS SINGLE '                                              coasting inclination / mem 81-84
  19.     status AS _BYTE '                                           0=destroyed 1=in flight 2=landed / mem 85
  20.     bstat AS _BYTE '                                            type of solution 0=none 1=evade 2=intercept 3=Planetfall / mem 86
  21.     bogey AS _BYTE '                                            target of intercept/evade solution / mem 87
  22.  
  23. DIM sh AS ship
  24.  
  25. sh.ap.pX = 78: sh.ap.pY = 7800: sh.ap.pZ = 78000: sh.Sp = 48.5: sh.Hd = 357: sh.In = 15: sh.status = 1
  26. PRINT sh.ap.pX, sh.ap.pY, sh.ap.pZ, sh.Sp, sh.Hd, sh.In, sh.status
  27. PRINT sh.op.pX, sh.op.pY, sh.op.pZ, sh.OSp, sh.OHd, sh.OIn, sh.Ostat
  28. DIM x AS STRING * 37
  29. m = _MEM(sh)
  30. PRINT m.ELEMENTSIZE
  31. _MEMGET m, m.OFFSET + 49, x 'remember to use m.ELEMENTSIZE & DO-LOOP for array shifts
  32. _MEMPUT m, m.OFFSET + 12, x
  33. PRINT sh.ap.pX, sh.ap.pY, sh.ap.pZ, sh.Sp, sh.Hd, sh.In, sh.status
  34. PRINT sh.op.pX, sh.op.pY, sh.op.pZ, sh.OSp, sh.OHd, sh.OIn, sh.Ostat
  35.  
  36.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: A _MEM newbie with a question on moving large blocks of data
« Reply #3 on: December 27, 2019, 07:36:03 am »
Thanks Steve, so many tools available that I can't find them all.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A _MEM newbie with a question on moving large blocks of data
« Reply #4 on: December 27, 2019, 07:54:37 am »
You can combine these 2 commands into one:

Code: [Select]
_MEMGET m, m.OFFSET + 49, x 'remember to use m.ELEMENTSIZE & DO-LOOP for array shifts
_MEMPUT m, m.OFFSET + 12, x

TO:

Code: [Select]
_MEMCOPY m, m.OFFSET +49, 37 TO m, m.OFFSET + 12
I haven’t got around to a tutorial on the extra mem commands yet, for the holidays, but I’ll try and remedy that after the New Years.  ;)
« Last Edit: December 27, 2019, 01:11:41 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: A _MEM newbie with a question on moving large blocks of data
« Reply #5 on: December 27, 2019, 10:19:59 am »
I haven’t got around to a tutorial on the extra mem commands yet, for the holidays, but I’ll try and remedy that after the New Years.  ;)

Can't wait!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: A _MEM newbie with a question on moving large blocks of data
« Reply #6 on: December 27, 2019, 12:51:58 pm »
I'm looking forward to it too. The ones you've done so far have helped take a lot of the mystique out of the commands, and have got the wheels turning in my head as to just what I can accomplish with it.