Knowledge Base

defBLOCK directive

The defBLOCK directive forces SPLat/PC to reserve a contiguous block of RAM for the subsequent defBYTEdefFLOATdefLONGdefTIME24 or defWORD memory allocations (but NOT defSEM). It is available in SPLat/PC V8.20.2 and later.

Syntax:

          defBLOCK      Value

Value is a required numeric constant or text defined with #EQU.

The next “Value” bytes worth of automatically allocated RAM will be allocated in an unbroken block.

Example:

When using Xwire or ModBus master you generally need to set aside a contiguous block of RAM for exchanging data with a remote device. The code to do that might look like this:

           defBLOCK       10     ;10 bytes of data sent out on Xwire
XW_Float1  defFLOAT              ;4 bytes
XW_Byte1   defBYTE               ;1 byte
XW_Float2  defFLOAT              ;4 bytes
XW_Sems    defBYTE               ;1 byte   = 10 bytes total

The “defBLOCK 10” guarantees that the next 4 RAM data items (occupying 10 bytes) will be allocated in a single, unbroken block of RAM. In the Xwire configuration table you would use XW_Float1 to identify the data area.

An error will be raised if SPLat/PC is unable to find enough free RAM.

Note: The associated RAM allocations must occupy the exact same number of bytes as the defBLOCK reserves. If you try to have more RAM bytes in the block, the results will be unpredictable.