Name
MemToTable -- return memory block contents as a table (V6.0)
Synopsis
t = MemToTable(id, type[, table])
Function
This function can be used to return the contents of a memory block (or part of a memory block) as a table. The type argument specifies the data type of the elements that should be read from the memory block and stored inside a table. This can be either #BYTE (1 byte), #SHORT (2 bytes), #INTEGER (4 bytes), #FLOAT (4 bytes), or #DOUBLE (8 bytes).

The optional table argument can be used to set additional parameters for the operation. The following table fields are currently recognized:

Items:
The number of items to be read from the memory block. Note that this is not a size in bytes, but an item count. So if you set the type argument to #INTEGER and set Items to 4, 16 bytes will be read from the memory block. Defaults to all items that are in the memory block.

Offset:
This tag can be used to specify an offset in bytes inside the memory block that defines where MemToTable() should start to read elements. Defaults to 0 which means read from the beginning of the memory block.

Signed:
If this tag is set to True, MemToTable() will treat all elements of type #BYTE, #SHORT, and #INTEGER as signed values. Defaults to False.

EndianSwitch:
If this tag is set to True, MemToTable() will switch byte order for all multi-byte data types. This can be useful if you need to convert between big and little endian values. Defaults to False.

To convert a table back into a memory block, use the TableToMem() function. See TableToMem for details.

Inputs
id
memory block to use
type
data type of the elements to read (see above)
table
optional: table configuring further parameters (see above)
Results
t
a table containing as many elements as specified in the Items tag
Example
AllocMem(1, 26)
For Local k = 0 To 25 Do Poke(1, k, 'A' + k, #BYTE)
Local t = MemToTable(1, #BYTE)
For Local k = 0 To 25 Do Print(Chr(t[k]))
This prints the alphabet from a memory block source.

Show TOC