Version .954
From QB64 Wiki
The _MEM variable type can be used when working with memory blocks. It has no variable type suffix. Effective version .954.
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:
- 0 = unknown(eg. created with _MEMNEW) or user-defined-types
- 1 = Integer types such as _BYTE, INTEGER, LONG, _INTEGER64 or _OFFSET
- 2 = _UNSIGNED variable types. Value must be added to the variable type value.(2 cannot be used by itself)
- 3 = ALL _UNSIGNED INTEGER type values.(add 1 + 2)
- 4 = Floating point types such as SINGLE, DOUBLE or _FLOAT
- 8 = STRING
- 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: