Many programming languages allow you to make direct changes to arrays at a memory level using a command called VARPTR.
https://www.youtube.com/watch?v=sdZahXk-e9Y
What I would like to do is:
a="" for i=0,8191 do a=a.."*" end memcpy(24576,varptr(a),8192) repeat flip() until forever |
Is this possible to do in PICO ?
Anyone? Anyone? Bueller?
But seriously, peek and poke are sandboxed, meaning that peeking outside the 0x0000 - 0x7FFF range of pico RAM gives 0 and poking outside the range returns an error. Try it. These are not even real RAM addresses, in that the OS uses actual RAM at these addresses for other things.
The underlying C the drives Lua does use pointers. However, these are not exposed to Lua users.
Foreach might be faster than a plain for loop. Depends how it was implemented. Also I think you can use memset, as long as you're filling a range of memory with the same value. The manual shows the syntax for each of these.
How fast do you need it to be?
Do you remember when PROT showed light speed travel ?
https://youtu.be/vByR8tGNFfM?t=133
I'd like it ... about that fast. :)
Failing that, as the scientist said. Perhaps a demonstration ?
A challenge - who can transfer a standard array - or list, say size 8192, filled with random numbers 0-255, fastest to memory location, oh, I don't know - 24576 ?
And the same ability to read back from 24576, 8192-bytes to the same standard array or list.
Someone mentioned earlier that it is the limitations of PICO-8 that make it so brilliant and beautiful.
With - the limitations of PICO-8, what can be accomplished in this ?
I just want to clarify terminology because this is the first page that comes up in Google for 'PICO-8 pointer' and the discussion above makes some assumptions that might confuse new programmers:
PICO-8 has pointers. In fact, almost every variable is a pointer to an object. Here's an example. If you write:
local a = {true} local b = a b[1] = false ? a[1] |
then you'll find that a[1] is now false, because a and b are pointers to the same object. Java and Python work the same way.
What PICO-8 lacks compared to C are pointer arithmetic and a weak type system. Although this means that certain low-level tricks can't be used, it also means that PICO-8 programs don't crash due to bugs in those programs. So, it is probably a good tradeoff. There are a few cases where you can use direct memory operations such as peek(), poke(), memcpy(), and memset() to set system state such as the palette and pixel values. But you can't use them to change the values of variables or data structures. There are some cases where it would be really convenient to do so, but...memory safety against corruption and crashes is a pretty good benefit to get from not allowing that.
[Please log in to post a comment]