Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DIM AT -- feature request
#1
PowerBasic has a very handy feature, the ability to dim at a certain address, for example suppose that you want to use a fixed-length string as a memory buffer
DIM buff As String * 256
DIM m(31) AS _Unsigned Long AT VARPTR(buff)

then you could access the array as usual but the values of the array m would be stored in the string buff
since QB64pe lacks arrays in Type, you could almost have that flexibility if you had Dim At
Reply
#2
The "DIM" statement presented there looks confusing.

Therefore after many years I'm glad QB64 instead has _MEM and _OFFSET.

I understand, use "m(1), m(2)" etc. to access portions in "buff", but yet this could be simplified with _MEMGET and _MEMPUT wrapped into convenience functions. Because we are all using 64-bit there would be no performance penalty for it.
Reply
#3
Hi @Jack

I just stumbled onto this in the issue tracker:
https://github.com/QB64-Phoenix-Edition/...1611346466

mechatronic3000 Wrote:I ran into a similar issue with my 2d physics engine. What I ended up doing is making the arrays into _MEM's (essentially making it a pointer) and I created some getters and setters to extract my data from the _MEM array.

Here is an example of what I did. You can make "test" and array in itself, however you have to do a _memnew for each element in the array.

Code: (Select All)

TYPE Example
Parameter1 AS INTEGER
Parameter2 AS INTEGER
Parameter3 AS _MEM
END TYPE

DIM test AS Example: test.Parameter3 = _MEMNEW(2 * 10) ' sizeof Integer * Number of elements

setter test, 2, 5
setter test, 6, 3
setter test, 9, 1

PRINT getter(test, 2)
PRINT getter(test, 6)
PRINT getter(test, 9)

SUB setter (test AS Example, index AS LONG, value AS INTEGER)
_MEMPUT test.Parameter3, test.Parameter3.OFFSET + (index * 2), value AS INTEGER
END SUB

FUNCTION getter% (test AS Example, index AS LONG)
getter = _MEMGET(test.Parameter3, test.Parameter3.OFFSET + (index * 2), INTEGER)
END FUNCTION

This might help you as it helped me.
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply




Users browsing this thread: 1 Guest(s)