access to memory and chip? Peek and Poke or ?

I remember back when I first started writing code with computers I used Q basic and a guy I went to school with was telling me about something
called “peak and poke” or some such thing that allowed you to get to memory addresses, etc, in qbasic if my memory doesn’t fail me.
Is there such a thing with Xojo? Just wondering ?


There probably isn’t a direct equivalent as Peek & Poke also used to give you access to the hardware on some versions of Basic.

If you are just wanting to manipulate data in memory then you could possibly use a memory block.

As Kevin says MemoryBlock is Xojo’s alternative.

This is how you Poke and Peek a string in a more traditional basic (in this case PureBasic):

s$ = "Hello, World!"
nSize.i = StringByteLength(s$,#PB_UTF8)
*Buffer = AllocateMemory(nSize)

And in Xojo (untested):

Dim s As String = "Hello, World!"
Dim nSize As Integer = s.LenB 
Dim buffer As New MemoryBlock(nSize)
buffer.StringValue(0,nSize) = s

True PEEK/POKE allowed you to address a specific memory address anywhere in the system. Modern day OS do not allow you to do that as your application can be running “anywhere” and even move in memory as it runs.

Anything you do with a MemoryBlock is relative to that block and within the protected bounds of that block, not within the application or systems entire memory map

@Tim Lee — I remember my Vic20 and my first Amstrad CPC 464 (then a 6128) where many “functions” were only available through peek&poke ! (I always remember an article describing this as “peek-poker” :-))

CPUs at the time were executing instructions and reading data directly from the RAM but modern CPUs do not. Instead, they read data ahead of time and put it in cache memory for faster execution/access. As a consequence, “peek-poker” is at best very slow if possible at all.

And when your computer had a BASIC in ROM, you could use Peek / Poke into BASIC entry points… set assembly languag programs in $300 and following, etc.

In short: no Peek or Poke in Xojo. Read above for MemoryBlock for some works on files in memory, eventually, if binaries or…

Thanks everyone for the answers. I never even thought about the cash and reading ahead. Makes perfect sense.