What is the difference between MATREAD and READ?

Do I need to understand the difference between MATREAD and READ? and please provide a simple example of where and how to use it.

+4
source share
2 answers

READ will read the disc entry and return it as a Dynamic Array . MATREAD will read the record from disk and return it as a Dimensioned Array .

So, the real trick is to determine which type of array is more applicable for your use case.

A Dynamic Array is essentially a string that uses specific byte markers to delimit each element (attribute / ambiguity / subcomputation). It is extremely easy to use, does not require prior declaration or sizing. On the other hand, if it can be slower than Dimensioned Array , mainly for large records, or when you randomly extract attributes from an array - O (n log n), I think. Sequential access is optimized and close to Dimensioned Arrays speed.

A Dimensioned Array is essentially an array of strings (or Dynamic Arrays in the case of UniVerse). It reads each attribute into an array position. Each position of the array will consist of a Dynamic Array only for positions with many / sub-currencies of this attribute. Dimensioned Arrays required you to declare them and the number of array positions in advance. Depending on the taste you are using, this can lead to a runtime error if you try to read a record with more attributes than the size of the array. O (1), on the other hand, retrieves attributes from an array regardless of your access pattern.

+8
source

MATREADU associates MATPARSE with READ. They invoke attributes of a dynamic array in a dimensional or fixed array. This can be more efficient if you often access the array and more convenient if you read the I-type from DICTionary. READV reads only one attribute of the array. Strive for clarity and optimization as needed.

Here is an example in UniVerse with 4 lines producing the same output:

 dim dimarr1(9), dimarr2(9) open 'VOC' else abort matread dimarr1 from 'OLDSTYLE' then print dimarr1(1) else abort read dynarr from 'OLDSTYLE' then print dynarr<1> else abort matparse dimarr2 from dynarr ; print dimarr2(1) readv dynatt from 'OLDSTYLE', 1 then print dynatt else abort end 
+2
source

Source: https://habr.com/ru/post/1480461/


All Articles