6.7.7 Memory Blocks

Memory blocks often represent character strings; For ways of storing character strings in memory see String representations. For other string-processing words see Displaying characters and strings.

A few of these words work on address unit blocks. In that case, you usually have to insert CHARS before the word when working on character strings. Most words work on character blocks, and expect a char-aligned address.

When copying characters between overlapping memory regions, use move. Cmove and cmove> tend to be slower than a well-implemented move.

move ( c-from c-to ucount – ) core “move”

Copy the contents of ucount aus at c-from to c-to. move works correctly even if the two areas overlap.

cmove ( c-from c-to u – ) string “c-move”

Copy the contents of ucount characters from data space at c-from to c-to. The copy proceeds char-by-char from low address to high address; i.e., for overlapping areas it is safe if c-to<=c-from.

cmove> ( c-from c-to u – ) string “c-move-up”

Copy the contents of ucount characters from data space at c-from to c-to. The copy proceeds char-by-char from high address to low address; i.e., for overlapping areas it is safe if c-to>=c-from.

fill ( c-addr u c – ) core “fill”

Store c in u chars starting at c-addr.

erase ( addr u –  ) core-ext “erase”

Clear all bits in u aus starting at addr.

blank ( c-addr u –  ) string “blank”

Store the space character into u chars starting at c-addr.

insert ( string length buffer size –  ) gforth-0.7 “insert”

inserts a string at the front of a buffer. The remaining bytes are moved on.

delete ( buffer size u –  ) gforth-0.7 “delete”

deletes the first u bytes from a buffer and fills the rest at the end with blanks.

compare ( c-addr1 u1 c-addr2 u2 – n ) string “compare”

Compare two strings lexicographically, based on the values of the bytes in the strings (i.e., case-sensitive and without locale-specific collation order orderings). If they are equal, n is 0; if the first string is smaller, n is -1; if the first string is larger, n is 1.

pad ( – c-addr  ) core-ext “pad”

c-addr is the address of a transient region that can be used as temporary data storage. At least 84 characters of space is available.