Navigation bar
  Start Previous page
 48 of 172 
Next page End  

ZBasic Language Reference
41
ZX Microcontroller Family
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.22 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
dimensions are deduced from the content of the initialization data and the lower bound of each index is
always 1.  The definition syntax for a Program Memory data item is:
{Public | Private | Dim} <name> as [New] <progmem-type>(<init-data>)
For Program Memory data items defined within a subroutine or function, the Public and Private keywords
are disallowed because they would serve no useful purpose.
The supported <progmem-type> items are:
Previous page Top Next page