MEMPUT - QB64 Wiki

MEMPUT

From QB64 Wiki

Revision as of 22:03, 30 January 2013 by Clippy (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The _MEMPUT statement writes data to a portion of a designated memory block at an OFFSET position.


Syntax:

_MEMPUT memory_block, byte_position, source_variable [AS type]


Parameters:

  • memory block is a _MEM variable type memory block name created by _MEMNEW or the _MEM function.
  • byte_position is the memory block.OFFSET start position plus any bytes needed to read specific values.
  • The source variable type designates the size and byte position it should be written to. It can be a variable, array or user defined type.
  • The source variable can be converted AS a specific variable type before being written to the memory block offset as bytes.


Usage:

  • The _MEMPUT statement is similar to the PUT file statement, but the byte position is required.
  • The memory block name.OFFSET returns the starting byte position of the block. Add bytes to move into the block.
  • The variable type held in the memory block can determine the next byte position to write a value.
  • LEN(variable) can determine the byte size of numerical or user defined variable types irregardless of the value held.
  • STRING values should be of a defined length. Variable length strings can actually move around in memory and not be found.


Example: _MEMPUT can be used just like POKE without DEF SEG.

DIM o AS _MEM o = _MEM(d&) _MEMPUT o, o.OFFSET + 1, 3 AS _UNSIGNED _BYTE 'POKE v = _MEMGET(o, o.OFFSET + 1, _UNSIGNED _BYTE) 'PEEK PRINT v 'prints 3 PRINT d& 'print 768 because the 2nd byte of d& has been set to 3 or 3 * 256


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page