Start Back Next End
  
ZBasic Language Reference
47
ZBasic Microcontrollers
a “sentinel” variable at both the beginning and the end of the group of persistent variables, decreasing the
likelihood of false positive or false negative indications.
Persistent variables have an associated property named DataAddress.  The value of this property is the
address of the data item in Persistent Memory.  The type of the property is UnsignedInteger for
compatibility with the PersistentPeek() subroutine.  
Example
Dim freq(1 to 10) as PersistentInteger
Dim addr as UnsignedInteger
addr = freq.DataAddress
It is possible, also, to use the DataAddress property to get the address of an element of a persistent
array.  To accomplish this, simply add parentheses following the property name and specify the index or
indices of the item of interest.  The example below will result in addr having the Persistent Memory
address of the fourth data value of the freq() array.
addr = freq(4).DataAddress
Persistent structures may also be defined, see Section 3.25 for more details.  A Persistent variable may
also be defined using Based keyword, see Section 3.21 for more details.
For compatibility with BasicX, an alternate syntax is also supported for defining persistent variables as
shown below.
{Public | Private | Dim} <name> as [New] <persistent-type>
Caution: although Persistent Memory data items can be modified, the memory in which they are stored
has a write cycle limit of approximately a million writes.  Writing to a particular address in excess of this
limit may cause the memory to become unreliable.  Also, writing to Persistent Memory is much slower
than writing to RAM-based variables.
The keyword New is optional except in BasicX compatibility mode when it is required.  The
<persistent-type> element specifies the type of persistent variable being defined and may  be one of
the following special types:
PersistentBoolean
PersistentByte
PersistentInteger
PersistentLong
PersistentSingle
BasicX Compatibility Note
In BasicX mode, all persistent variables must be defined at the module level and neither
arrays nor structures of persistent variables are supported.  Also, the DataAddress
property cannot be used to determine the address of a persistent variable.
2.10 Program Memory Data Items
It is often useful to have available initialized arrays of data that are stored in Program Memory.  This is
advantageous for two reasons.  Firstly, you don’t need run-time code to initialize the arrays and,
secondly, you don’t use up the more scarce RAM space for data that seldom, if ever, changes.
You define an initialized Program Memory data item in a manner similar to the way that you define RAM-
based data items.  There are two differences, however.  Firstly, you need to specify a data source from
which the array is initialized.  Secondly, you don’t explicitly specify the array dimensions.  Instead, the
Previous page Top Next page