Documentation Comments
Use this form to comment on this topic. You can also provide any general observations about the Online Documentation, or request that additional information be added in a future release.
Reality V15.0 ()
Dynamic Arrays vs. Dimensioned Arrays (DataBasic) (m618702+dynamicvsdimensionedarrays.htm)
DataBasic lets you process sets of values in the form of dynamic arrays or as individual array elements in dimensioned arrays. This topic discusses the tradeoffs involved in each format.
Dynamic arrays are primarily useful in interfacing to Reality file items. By specifying a single variable name, you can read or write an entire item, or access individual parts of an item easily.
Referencing a dynamic array and scanning it looking for individual elements may sometimes be inefficient, depending on the application.
For example, to extract attribute 10 from an item, DataBasic first scans over attributes 1 through 9. When replacing data in an item, DataBasic passes by all the data preceding the replacement, copies in the new value and then appends all the data that came after the attribute. This continual scanning becomes inefficient when you are accessing a large number of elements or processing a large item.
In such cases, it is better to read the item into a dimensioned array (using the MATREAD statement). MATREAD places each attribute of the item into separate variable locations that can be accessed individually, without scanning the item. This is particularly useful if several attributes need to be changed, because you can modify attributes without moving the rest of the item.
You can still use dynamic array references to extract, delete, insert and replace attributes, values and subvalues. For example, if the item is stored as a dynamic array, the expression ITEM<3,2,4> accesses the fourth subvalue in the second value in the third attribute. On the other hand, if the item is stored as a dimensioned array, the expression ITEM(3)<1,2,4> accesses the same element.
This method has its disadvantages too. Because there is a separate descriptor for each element in the array, it uses more variable descriptor space. It also uses more free space, because each attribute may have its own buffer in free space. In addition, items must be disassembled for a MATREAD and reassembled with a MATWRITE, which takes more time than a simple READ or WRITE.
Use the following rules as guidelines in determining whether to use dynamic or dimensioned arrays.