Difference between revisions of "MEMELEMENT"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 7: Line 7:
  
 
* The ''reference variable'' parameter designates the existing variable name using the memory block.
 
* The ''reference variable'' parameter designates the existing variable name using the memory block.
 +
* _MEMELEMENT is the same as [[_MEM]] but in an array it returns the specifications of an element, not the entire array.
 
* All values created by memory functions MUST be freed using [[_MEMFREE]] with a valid [[_MEM]] variable type.
 
* All values created by memory functions MUST be freed using [[_MEMFREE]] with a valid [[_MEM]] variable type.
 +
 +
 +
''Example:'' Comparing the specifications returned by [[_MEM]] and _MEMELEMENT from an array.
 +
{{CodeStart}} '' ''
 +
{{Cl|DIM}} a(1 {{Cl|TO}} 100) {{Cl|AS}} {{Cl|_BYTE}}
 +
 +
{{Cl|DIM}} m1 {{Cl|AS}} {{Cl|_MEM}}
 +
{{Cl|DIM}} m2 {{Cl|AS}} {{Cl|_MEM}}
 +
 +
m1 = {{Cl|_MEM (function)|_MEM}}(a(50)) 'function returns information about array up to specific element
 +
{{Cl|PRINT}} m1.OFFSET, m1.SIZE, m1.TYPE, m1.ELEMENTSIZE
 +
 +
m2 = {{Cl|_MEMELEMENT}}(a(50)) 'function returns information about the specific element
 +
{{Cl|PRINT}} m2.OFFSET, m2.SIZE, m2.TYPE, m2.ELEMENTSIZE
 +
 +
{{Cl|END}} '' ''
 +
{{CodeEnd}}
 +
: Output using VERSION .954 ONLY type values
 +
{{OutputStart}}28377205        51        3        1
 +
28377205        1        3        1 {{OutputEnd}}
 +
: ''Explanation:'' [[_MEM]] returns the info about the array to that element while _MEMELEMENT returns info about that element only.
 +
::* [[_MEM]] value returns the array .SIZE  as 51 bytes from the first array index .OFFSET.
 +
::* [[_MEMELEMENT]] value returns the array element .SIZE as one byte.
  
  

Revision as of 17:29, 20 August 2012

The _MEMELEMENT function returns a _MEM block referring to a variable's memory ,but not past it.


Syntax

memory_block = _MEMELEMENT(reference_variable)


  • The reference variable parameter designates the existing variable name using the memory block.
  • _MEMELEMENT is the same as _MEM but in an array it returns the specifications of an element, not the entire array.
  • All values created by memory functions MUST be freed using _MEMFREE with a valid _MEM variable type.


Example: Comparing the specifications returned by _MEM and _MEMELEMENT from an array.

DIM a(1 TO 100) AS _BYTE DIM m1 AS _MEM DIM m2 AS _MEM m1 = _MEM(a(50)) 'function returns information about array up to specific element PRINT m1.OFFSET, m1.SIZE, m1.TYPE, m1.ELEMENTSIZE m2 = _MEMELEMENT(a(50)) 'function returns information about the specific element PRINT m2.OFFSET, m2.SIZE, m2.TYPE, m2.ELEMENTSIZE END

Output using VERSION .954 ONLY type values

28377205 51 3 1 28377205 1 3 1

Explanation: _MEM returns the info about the array to that element while _MEMELEMENT returns info about that element only.
  • _MEM value returns the array .SIZE as 51 bytes from the first array index .OFFSET.
  • _MEMELEMENT value returns the array element .SIZE as one byte.


See also:



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