{{DISPLAYTITLE:_MEMPUT}}
The '''_MEMPUT''' statement writes data to a portion of a designated memory block at an OFFSET position.


{{PageSyntax}}
::: '''_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)|_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, [[arrays|array]] or user defined type.
* The ''source variable'' can be converted [[AS]] a specific variable ''[[TYPE|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 [[type]]s 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]].
{{CodeStart}} '' ''
{{Cl|DIM}} o {{Cl|AS}} {{Cl|_MEM}}
o = {{Cl|_MEM (function)|_MEM}}(d&amp;)
{{Cl|_MEMPUT}} o, o.OFFSET + 1, 3 {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|_BYTE}}  'POKE
v = {{Cl|_MEMGET (function)|_MEMGET}}(o, o.OFFSET + 1, {{Cl|_UNSIGNED}} {{Cl|_BYTE}}) 'PEEK
{{Cl|PRINT}} v 'prints 3
{{Cl|PRINT}} d&amp; 'print 768 because the 2nd byte of d&amp; has been set to 3 or 3 * 256 '' ''
{{CodeEnd}}


''See also:''
* [[_MEMGET]], [[_MEMGET (function)]]
* [[_MEM]], [[_MEM (function)]]
* [[_MEMIMAGE]], [[_MEMNEW]]
* [[_MEMFREE]], [[_MEMCOPY]]


{{PageNavigation}}