Version .954 - QB64 Wiki

Version .954

From QB64 Wiki

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

The _MEM variable type can be used when working with memory blocks. It has no variable type suffix. Effective version .954.


Syntax:

DIM m AS _MEM


Variable TYPE:

  • Memory DOT values are actually part of the built in memory variable type in QB64. The following TYPE is built in:

TYPE memory_type OFFSET AS _OFFSET 'start location of block(changes with byte position) SIZE AS _OFFSET 'size of block remaining at offset(changes with position) TYPE AS LONG 'type description of variable used(never changes) ELEMENTSIZE AS _OFFSET 'byte size of values inside the block(never changes) IMAGE AS LONG 'the image handle used when _MEMIMAGE(handle) is used END TYPE The above TYPE is for clarification purposes only. It is not required to use _MEM!


Usage:

  • The _MEM type contains the following read only DOT elements where name is the _MEM variable name:
name.OFFSET is the current start position in the memory block AS _OFFSET. Add bytes to change position.
name.SIZE is the remaining size of the block at current position in bytes AS _OFFSET
name.TYPE is the type (represented as bits combined to form a value) AS LONG:
_MEM Version .954 .TYPE METHOD ONLY:
name.ELEMENTSIZE is the _BYTE size of the elements within the block AS _OFFSET
  • 1 = _BYTE or unfixed STRING values have a size of 1 byte.
  • 2 = INTEGER values have an element size of 2 bytes
  • 4 = LONG integer and SINGLE float values have an element size of 4 bytes
  • 8 = DOUBLE float and _INTEGER64 values have an element size of 8 bytes
  • 32 = _FLOAT values have an element size of 32 bytes
  • LEN = _OFFSET and fixed length STRING byte sizes vary so use LEN for the number of bytes.
  • Note: _OFFSET values cannot be cast to other variable types reliably! _MEM is a reserved custom variable type!
  • _MEM cannot reference variable length STRING variable values! String values must be designated as a fixed LEN.


Example: Converts the current destination SCREEN 13 image memory altered by PSET to a STRING value. SCREEN 13 only!

SCREEN 13 PSET (0, 0), ASC("H") 'top left corner of screen PSET (1, 0), ASC("E") PSET (2, 0), ASC("L") PSET (3, 0), ASC("L") PSET (4, 0), ASC("O") DIM m AS _MEM m = _MEMIMAGE(0) 'copy the screen memory to m x1$ = _MEMGET(m, m.OFFSET, STRING * 5) 'get at block start position LOCATE 2, 1:PRINT LEN(x1$) 'prints 5 bytes as size is STRING * 5 PRINT x1$ 'prints HELLO as ASCII character values PRINT m.OFFSET; m.SIZE; m.TYPE; m.ELEMENTSIZE _MEMFREE m

5 HELLO 5448320 6400 4609 1

Explanation: When a numerical _BYTE value is converted to a STRING, each byte is converted to an ASCII character. The QB64 IDE will capitalize _MEM dot values.

m.SIZE = 320 * 200 = 6400 bytes m.TYPE = 4096 + 512 + 1 = 4609 (type = _UNSIGNED _BYTE) m.ELEMENTSIZE = 1 byte

See also:

Return to _MEM page

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