Start Back Next End
  
ZBasic Language Reference
95
ZBasic Microcontrollers
Dynamically Allocated String Storage Layout
Offset
Length
Description
0
1
The current string length, in bytes.
1
1
A marker identifying the string location:
  &He0 – RAM (allocated from the heap)
  &He2 – Program Memory
  &He3 – Persistent Memory
&He4 – RAM (not allocated)
  &He5 – RAM (not allocated, limited to 2 chars max.)
  &He6 – RAM (pointer refers to a statically allocated string)
2
2
For type &He5, the one or two characters of the string.
For type &He6, the address of a statically allocated string variable (see below).
For all other types, the address of the first character of the string.
For statically allocated strings, including Bounded Strings and Fixed Length strings, the space allocated
for the variable is used in the following manner:
Statically Allocated String Storage Layout
Offset
Length
Description
0
1
The current string length, in bytes.
1
1
A marker identifying the string characteristics:
  &H00 – fixed allocation, variable length
&Hff – fixed allocation, fixed length
2
N
The characters of the string where N is the defined string length.
For Fixed Length strings the byte at offset zero will be constant and the byte at offset 1 will have the value
&Hff to indicate that it is a Fixed Length string.
Fixed-Length String Storage Layout
Offset
Length
Description
0
1
The string length, in bytes.
1
1
A marker identifying the string characteristics:
  &Hff – fixed allocation, fixed length
2
N
The characters of the string where N is the fixed string length.
3.28.3 String Address and String Type
Generally, you needn’t be concerned about the technical details regarding strings described in the
preceding section.  For certain special situations, however, it may be useful directly access a string
variable’s inner data components.  The StrAddress() function works with all of the string types
described above and will return the address of the first character of the string storage.  Note, however,
that for dynamically allocated strings if the string’s length is zero the returned address will be of no use (it
will generally be zero).  Moreover, the returned address may be an address in RAM, in Program Memory
or in Persistent Memory.  Depending on where the string’s characters are stored you must use different
System Library Functions to retrieve the string’s characters.  You can use the System Library function
StrType() to determine the nature of the string’s storage.  It will return the second byte of the string
variable’s storage space.  See the tables above for the values and their meaning.
BasicX Compatibility Note
In BasicX compatibility mode, neither StrAddress() nor StrType() is available.
Previous page Top Next page