New string

Purpose: Create a new string.

 new-string <variable> length <length>

New empty string <variable> of length <length> is allocated. The <variable> is an empty string (i.e. ""), however <length> bytes are allocated.

new-string is useful when you need to create a block of memory of certain length, and then change its individual bytes (such as with set-string).

Note that if <length> is a numeric literal, then <variable> will be allocated statically if <length> is lesser than 1024 bytes; this makes such strings faster at run time, especially for server processes. In all other cases, <variable> is dynamically allocated from the heap.

Also note that <variable> (like all strings, text, binary and however allocated) has an implicit null byte placed after <length> bytes.
Examples
Create new string and alter it with new content and to be of length 2:
 new-string my_string length 30
 set-string my_string[0] = 'A'
 set-string my_string[1] = 'B'
 set-string my_string length 2
 print-out my_string new-line

The output of above code would be "AB".


Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.