pmem_read — Read persistent memory


Variation 1
void pmem_read(uint8 offset, <anytype> *variable);

Update the variable pointed by *variable with the value of type and size defined by <anytype>, located in the position offset from the persistent memory RAM array.

Variation 2
uint8 pmem_read(uint8 offset);

Read the uint8 value from position offset of the persistent memory RAM array.


  • offset: Position of the persistent memory array, starting from 0, from which a value should be read. Note: on Variation 2 the offset is passed as direct parameter of the opcode, therefore stack values can't be used.
  • <anytype> *variable: Pointer to an variable of type <anytype>.
<anytype> can be: int8, uint8, int16, uint16, int32, uint32, fix32 or any of its aliases.
Byte Size of Variable Types
int8, uint8 1 byte
int16, uint16 2 bytes big-endian
int32, uint32, fix32 4 bytes big-endian

Return Value

  • Variation 1 does not returns any value.
  • Variation 2 returns an uint8 value from the position offset.

Persistent Memory

Persistent Memory Flow

The persistent memory is an array of 128 bytes that can be used to store data structures such that they can continue to be accessed even after the end of the GPC script that created or last modified them.

For performance reasons the operations pmem_read() and pmem_write() are performed in RAM, therefore the persistent memory contents should first be loaded into RAM space by pmem_load() and, if modified, saved with pmem_save().


Example #1 pmem_read() example

bool checkbox_value;
uint8 radiobox_value;
uint8 combobox_value;
int spinbox_value;
fix32 spinboxf_value;
int slider_value;
int dial_value;
init {
    pmem_load(); // Load permanent memory before use any pmem operation
    // Store the values from the permanent memory into variables.
    checkbox_value = (pmem_read(0) >> 7) & 0b1;
    radiobox_value = pmem_read(1);
    combobox_value = pmem_read(2);
    pmem_read(3, &spinbox_value);
    pmem_read(5, &spinboxf_value);
    pmem_read(9, &slider_value);
    pmem_read(11, &dial_value);

See Also

t2/pmem_read.txt · Last modified: 2016/12/02 06:17 by J2Kbr