QB64 Phoenix Edition
DIM AT -- feature request - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2)
+--- Thread: DIM AT -- feature request (/showthread.php?tid=1902)



DIM AT -- feature request - Jack - 08-14-2023

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


RE: DIM AT -- feature request - mnrvovrfc - 08-14-2023

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.


RE: DIM AT -- feature request - grymmjack - 08-15-2023

Hi @Jack

I just stumbled onto this in the issue tracker:
https://github.com/QB64-Phoenix-Edition/QB64pe/issues/354#issuecomment-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.