LabVIEW converts data from the format in memory to a form more suitable for writing to or reading from a file. This more suitable format is called flattened data.
Because LabVIEW stores strings, arrays, and paths in handles (pointers to pointers in separate regions of memory), clusters that contain these strings and arrays are noncontiguous. In general, LabVIEW stores data in tree form. For example, LabVIEW stores a cluster as a double-precision, floating-point number and a string as an 8-byte floating-point number followed by a 4-byte handle to the string. LabVIEW does not store the string data adjacent to the extended-precision, floating-point number in memory. Therefore, to write the cluster data to disk, LabVIEW must get the data from two different places. With a cluster that contains many strings, arrays, and/or paths, LabVIEW stores the data in many different places.
When you save data to a file, LabVIEW flattens the data into a single string before saving it. Flattening data makes the data from an arbitrarily complex cluster contiguous rather than stored in several places. When LabVIEW loads data from a file, LabVIEW must perform the reverse operation, reading a single string and unflattening it into its internal, possibly noncontiguous, form.
LabVIEW normalizes the flattened data to a standard form so VIs that run on any platform can use the data. LabVIEW stores flattened numeric data in big-endian form (most significant byte first), and stores flattened extended-precision, floating-point numbers as 16-byte quantities.
When writing data to a file for use by an application that was not created using LabVIEW or when reading data from a file produced by an application that was not created using LabVIEW, you can transform the data into little-endian (least significant byte first) or big-endian form after flattening or before unflattening. Windows-based applications typically expect numeric data to be in little-endian form.
Use the Flatten To String and Unflatten From String functions to flatten and unflatten data just as LabVIEW does internally when LabVIEW saves and loads data.
The flattened form of a piece of data does not encode the type of the data. LabVIEW stores this information in a type descriptor. The Unflatten From String function requires you to wire a data type as an input so the function can decode the string properly.
Use the variant data type to work with data independently of data type instead of flattening the data when you write to memory and unflattening the data when you read from memory. Use the Variant functions to create and manipulate variant data.
Note��If you use the Flatten To String function on variant data, LabVIEW will flatten the variant and all its contents, including attributes. However, if you use the Variant To Flattened String function, LabVIEW flattens only the variant and discards any attributes. |
The flattened form of any numeric type and Boolean type stores the data only in big-endian format. For example, a 32-bit integer with a value of �19 is flattened to FFFF FFED. A double-precision floating-point number with a value equal to 1/4 is flattened to 3FD0 0000 0000 0000. A Boolean value of TRUE is any nonzero value. A Boolean value of FALSE is 00.
The flattened form for extended-precision numbers is the 128-bit extended-precision, floating-point format. When you save extended-precision numbers to disk, LabVIEW stores them in this format.
Because strings and paths have variable sizes, a flattened 32-bit integer that records the length in bytes precedes the flattened form. For example, a string type with value ABC is flattened to 0000 0003 4142 43. For strings, the flattened format is similar to the format the string takes in memory.
However, paths do not have a length value preceding them when LabVIEW stores them in memory, so this value comes from the actual size of the data in memory and prefixes the value when LabVIEW flattens the data. This length is preceded by four characters: PTH0.
For example, a path with value C:\File is flattened to 5054 4830 0000 000B 0000 0002 0143 0466 696C 65.
5054 4830 indicates PTH0. 0000 000B indicates 11 bytes total. 0000 is the type. 0002 is the number of components. 0143 indicates the letter C as a Pascal string. 0466 696C 65 indicates the word File as a Pascal string.
Flattened 32-bit integers that record the size, in elements, of each of the dimensions of an array precede the data for a flattened array. The slowest varying dimension is first, followed successively by the faster varying dimensions, just as the dimension sizes are stored in memory. The flattened data follows immediately after these dimension sizes in the same order in which LabVIEW stores them in memory. The following example shows a 2D array of six 8-bit integers.
{ {1, 2, 3}, {4, 5, 6} } is flattened to 0000 0002 0000 0003 0102 0304 0506.
The following example shows a flattened 1D array of Boolean variables.
{T, F, T, T} is flattened to 0000 0004 0100 0101. The preferred value for TRUE is 01.
A flattened cluster is the concatenation, in cluster order, of the flattened data of its elements. For example, a flattened cluster of a 16-bit integer of value 4 (decimal) and a 32-bit integer of value 12 is 0004 0000 000C.
A flattened cluster of a string ABC and a 16-bit integer of value 4 is 0000 0003 4142 4300 04.
A flattened cluster of a 16-bit integer of value 7, a cluster of a 16-bit integer of value 8, and a 16-bit integer of value 9 is 0007 0008 0009.
LabVIEW flattens waveforms like clusters.
LabVIEW stores the majority of flattened refnums as flattened 32-bit integers, which represent an internal LabVIEW data structure.
You can classify the remaining refnums by their refnum type code.
Type codes 0xE, 0xF and 0x15 are refnums that store their data as a flattened string. This string contains the value of the refnum tag, and can be empty (4 bytes of zero).
Type codes 0x1A, 0X1C, and 0x1D concatenate, in the following order:
LabVIEW flattens a LabVIEW class according to the following general format:
level in hierarchy | class name | version list | private data |
Note��If level in hierarchy is 0, the object is an instance of LabVIEW Object, and LabVIEW excludes the other three fields from the string. |
Note��If level in hierarchy is 1 and the version is 0, the flattened data represents the default data of the class, and LabVIEW excludes the remaining field from the string. |