updating oE poke

Writing to Memory

poke

<built-in> procedure poke(atom addr, object x) 

stores one or more bytes, starting at a memory location.

Parameters:
  1. addr : an atom, the address at which to store
  2. x : an object, either a byte or a non empty sequence of bytes.
Errors:

Poking in memory you do not own may be blocked by the OS, and cause a machine exception. The -D SAFE option will make poke catch this sort of issues.

Comments:

The lower 8-bits of each byte value (such as remainder(x, 256)) is actually stored in memory.

It is faster to write several bytes at once by poking a sequence of values, than it is to write one byte at a time in a loop.

Writing to the screen memory with poke can be much faster than using puts or printf, but the programming is more difficult. In most cases the speed is not needed. For example, the Euphoria editor, ed, never uses poke.

Example 1:
 a = allocate(100)   -- allocate 100 bytes in memory 
 
-- poke one byte at a time: 
poke(a, 97) 
poke(a+1, 98) 
poke(a+2, 99) 
 
-- poke 3 bytes at once: 
poke(a, {97, 98, 99}) 
Example 2:

demo/callmach.ex

See Also:

Using Data Bytes, peek, peeks, poke4, allocate, free, poke2, mem_copy, mem_set

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu