MEM (function): Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_MEM (function)}} The _MEM function returns a _MEM block referring to the largest possible continuous memory region beginning at a variable's offset. {{PageSyntax}} : {{Parameter|memoryBlock}} = _MEM({{Parameter|referenceVariable}}) ===Unsecure syntax=== : {{Parameter|memoryBlock}} = _MEM({{Parameter|offset}}, {{Parameter|byteSize}}) {{Parameters}} * The {{Parameter|memoryBlock}} created will hold the {{Parameter|referenceVariable}} or a...")
 
No edit summary
Line 10: Line 10:




{{Parameters}}
{{PageParameters}}
* The {{Parameter|memoryBlock}} created will hold the {{Parameter|referenceVariable}} or [[arrays|array]] value(s), type and byte size in a separate memory area.
* The {{Parameter|memoryBlock}} created will hold the {{Parameter|referenceVariable}} or [[arrays|array]] value(s), type and byte size in a separate memory area.
* The secure syntax {{Parameter|referenceVariable}} is an existing variable's referenced memory block.
* The secure syntax {{Parameter|referenceVariable}} is an existing variable's referenced memory block.
Line 24: Line 24:
{{PageExamples}}
{{PageExamples}}
''Example:'' Assigning values to reference variables in memory.
''Example:'' Assigning values to reference variables in memory.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|DIM}} {{Cl|SHARED}} m(3) {{Cl|AS}} {{Cl|_MEM}}
{{Cl|DIM}} {{Cl|SHARED}} m(3) {{Cl|AS}} {{Cl|_MEM}}
{{Cl|DIM}} {{Cl|SHARED}} Saved(3)
{{Cl|DIM}} {{Cl|SHARED}} Saved(3)
Line 56: Line 56:
{{Cl|_MEMPUT}} m(2), m(2).OFFSET, Saved(2)
{{Cl|_MEMPUT}} m(2), m(2).OFFSET, Saved(2)
{{Cl|_MEMPUT}} m(3), m(3).OFFSET, Saved(3)
{{Cl|_MEMPUT}} m(3), m(3).OFFSET, Saved(3)
{{Cl|END SUB}} '' ''
{{Cl|END SUB}}  
{{CodeEnd}}{{small|Code by SMcNeill}}
{{CodeEnd}}{{small|Code by SMcNeill}}


Line 62: Line 62:
{{PageSeeAlso}}
{{PageSeeAlso}}
* [[_MEM]] {{text|(variable type)}}
* [[_MEM]] {{text|(variable type)}}
* [[_MEMNEW]], [[_MEMCOPY]]
* [[_MEMNEW]], [[_MEMCOPY]], [[_MEMFREE]]
* [[_MEMGET]], [[_MEMPUT]]
* [[_MEMGET]], [[_MEMPUT]][[_MEMFILL]]
* [[_MEMFILL]], [[_MEMIMAGE]]
* [[_MEMIMAGE]], [[_MEMSOUND]]
* [[_MEMFREE]]




{{PageNavigation}}
{{PageNavigation}}
[[Category:Latest]]

Revision as of 11:53, 26 June 2022

The _MEM function returns a _MEM block referring to the largest possible continuous memory region beginning at a variable's offset.


Syntax

memoryBlock = _MEM(referenceVariable)

Unsecure syntax

memoryBlock = _MEM(offset, byteSize)


Parameters

  • The memoryBlock created will hold the referenceVariable or array value(s), type and byte size in a separate memory area.
  • The secure syntax referenceVariable is an existing variable's referenced memory block.
  • The unsecure syntax's designated offset and byteSize cannot be guaranteed. Avoid if possible.


Description

  • The memoryBlock _MEM type variable holds the following read-only elements: OFFSET, SIZE, TYPE and ELEMENTSIZE.
  • All values created by memory functions MUST be freed using _MEMFREE with a valid _MEM variable type.
  • _MEM function cannot reference variable length STRING variable values. String values must be designated as a fixed-length string.


Examples

Example: Assigning values to reference variables in memory.

DIM SHARED m(3) AS _MEM
DIM SHARED Saved(3)

m(1) = _MEM(x)
m(2) = _MEM(y)
m(3) = _MEM(z)

x = 3: y = 5: z = 8
PRINT x, y, z
Save x, y, z
x = 30: y = 50: z = 80
PRINT x, y, z

RestoreIt
PRINT x, y, z

_MEMFREE m(1)
_MEMFREE m(2)
_MEMFREE m(3)
END

SUB Save (n1, n2, n3)
Saved(1) = n1
Saved(2) = n2
Saved(3) = n3
END SUB

SUB RestoreIt
_MEMPUT m(1), m(1).OFFSET, Saved(1)
_MEMPUT m(2), m(2).OFFSET, Saved(2)
_MEMPUT m(3), m(3).OFFSET, Saved(3)
END SUB 
Code by SMcNeill


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link