MEMGET (function): Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "{{DISPLAYTITLE:_MEMGET (function)}} The _MEMGET function returns a value from a specific memory block name at the specified OFFSET using a certain variable type. {{PageSyntax}} : {{Parameter|returnValue}} = _MEMGET({{Parameter|memoryBlock}}, {{Parameter|bytePosition}}, {{Parameter|variableType}}) {{Parameters}} * Returns a value of the {{Parameter|variableType}} designated. The holding variable must match that TYPE. * {{Parameter|memoryBlock}} is a _MEM...") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
{{ | {{PageParameters}} | ||
* Returns a value of the {{Parameter|variableType}} designated. The holding variable must match that [[TYPE]]. | * Returns a value of the {{Parameter|variableType}} designated. The holding variable must match that [[TYPE]]. | ||
* {{Parameter|memoryBlock}} is a [[_MEM]] variable type memory block name created by [[_MEMNEW]] or the [[_MEM (function)|_MEM]] function. | * {{Parameter|memoryBlock}} is a [[_MEM]] variable type memory block name created by [[_MEMNEW]] or the [[_MEM (function)|_MEM]] function. | ||
* {{Parameter|bytePosition}} is the {{Parameter|memoryBlock}}.[[OFFSET]] memory start position plus any bytes to move into the block. | * {{Parameter|bytePosition}} is the {{Parameter|memoryBlock}}.[[OFFSET]] memory start position plus any bytes to move into the block. | ||
* {{Parameter|variableType}} is a variable [[TYPE]] like [[_BYTE]], [[INTEGER]], [[SINGLE]], [[DOUBLE]], etc. | * {{Parameter|variableType}} is a variable [[TYPE]] like [[_BYTE]], [[INTEGER]], [[SINGLE]], [[DOUBLE]], etc. | ||
Line 16: | Line 16: | ||
{{PageDescription}} | {{PageDescription}} | ||
* {{Parameter|memoryBlock}}.[[OFFSET]] returns the starting byte position of the block. Add bytes to move into the block. | * {{Parameter|memoryBlock}}.[[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 {{Parameter|bytePosition}} to read. | * The variable type held in the memory block can determine the next {{Parameter|bytePosition}} to read. | ||
* [[LEN]] can be used to determine the byte size of numerical or user defined | * [[LEN]] can be used to determine the byte size of numerical or user defined [[Variable Types]] regardless 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. | * [[STRING]] values should be of a defined length. Variable length strings can actually move around in memory and not be found. | ||
* '''_MEMGET variable values that are assigned a variable [[type]] other than a memory type do not need to be freed.''' | * '''_MEMGET variable values that are assigned a variable [[Variable Types|type]] other than a memory type do not need to be freed.''' | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' [[DEF SEG]] and [[VARPTR]] are no longer necessary to do things in memory just like [[POKE]] and [[PEEK]] do. | ''Example:'' [[DEF SEG]] and [[VARPTR]] are no longer necessary to do things in memory just like [[POKE]] and [[PEEK]] do. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|DIM}} o {{Cl|AS}} {{Cl|_MEM}} | {{Cl|DIM}} o {{Cl|AS}} {{Cl|_MEM}} | ||
o = {{Cl|_MEM (function)|_MEM}}(d&) 'OLD... o% = VARPTR(d&) | o = {{Cl|_MEM (function)|_MEM}}(d&) 'OLD... o% = VARPTR(d&) |
Latest revision as of 20:26, 26 January 2024
The _MEMGET function returns a value from a specific memory block name at the specified OFFSET using a certain variable type.
Syntax
- returnValue = _MEMGET(memoryBlock, bytePosition, variableType)
Parameters
- Returns a value of the variableType designated. The holding variable must match that TYPE.
- memoryBlock is a _MEM variable type memory block name created by _MEMNEW or the _MEM function.
- bytePosition is the memoryBlock.OFFSET memory start position plus any bytes to move into the block.
- variableType is a variable TYPE like _BYTE, INTEGER, SINGLE, DOUBLE, etc.
Description
- memoryBlock.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 bytePosition to read.
- LEN can be used to determine the byte size of numerical or user defined Variable Types regardless 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.
- _MEMGET variable values that are assigned a variable type other than a memory type do not need to be freed.
Examples
Example: DEF SEG and VARPTR are no longer necessary to do things in memory just like POKE and PEEK do.
DIM o AS _MEM o = _MEM(d&) 'OLD... o% = VARPTR(d&) _MEMPUT o, o.OFFSET + 1, 3 AS _UNSIGNED _BYTE 'a POKE v = _MEMGET(o, o.OFFSET + 1, _UNSIGNED _BYTE) 'a PEEK PRINT v 'prints 3 PRINT d& 'prints 768 because the 2nd byte of d& has been set to 3 or 3 * 256 _MEMFREE o |
- Explanation: The memory block and OFFSET are given by _MEMPUT and the _MEMGET function, with the designated type.
See also