MemBFill, MemWFill, MemLFill, MemSet and MemZero Command

Purpose

Fills a memory area with a specified value.

Syntax

MemBFill[(] addr, count, value [)]
MemWFill[(] addr, count, value [)]
MemLFill[(] addr, count, value [)]

MemSet[(] addr, count, value [)]

MemZero[(] addr, count [)]

addr: address
count: Int32 expression
value: byte, Int16 or Int32 expression

Description

All these commands fill a memory area, starting from the address addr, with count occurences of a particular value; in the case of MemZero, this value is always zero, whereas with the rest it can be specified in the value parameter.

MemBFill, MemSet and MemZero all write the value as a byte, while MemWFill writes it as a 16-bit Integer and MemLFill as a 32-bit Integer.

With all these commands, the parameters can be enclosed in brackets or not as desired.

Example

Local addr% = mAlloc(200)

MemBFill addr%, 200, 2

MemSet   addr%, 200, 1

MemZero  addr%, 200

MemWFill addr%, 100, 102

MemLFill addr%, 50, 15677

Remarks

One use for all these commands is to fill an array, but ArrayFill is much better suited, as shown below:

Local a%(1 To 200), n%, t#

t# = Timer

For n% = 1 To 10000 : MemLFill V:a%(1), 200, 2 : Next n

Trace a%(1)

Debug "MemLFill time:" & Timer - t#

t# = Timer

For n% = 1 To 10000 : ArrayFill a%(), 2 : Next n

Debug "ArrayFill time:" & Timer - t#

Trace a%(1)

Debug.Show

{Created by Sjouke Hamstra; Last updated: 02/03/2017 by James Gaite}