LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variant Data vs Flattened to String

Solved!
Go to solution

Hi All,

I haven't worked much with the variant data type in LabVIEW and after reading some basics about it, I am wondering what is the basic difference between a variant data type and a flattened string.

 

I read somewhere that variant data types also contain the meta data which includes the type of the data it has and still we have to wire the data type to the function "Variant to Data'. Why?

 

What is the use case of variant data type? I am basically thinking of a use case where flattened string can't do a job what variant data type can do.

 

Thanks,

Ritesh

Message 1 of 10
(7,201 Views)

A variant data type is a generic binary object.  A flattened string is a binary object converted into a form suitable for serialization (e.g. reading or writing to a serial port or writing to a pipe).

 

Variants do have the type information imbedded in them (see the tools a <vi.lib>\Utility\VariantDataType).  However, this information is only available at run-time.  Since wires are strictly typed, the compiler needs to know that the output wire is when it is compiled, so the input data type is needed.

 

Variants transforms are typically faster than flatten/unflatten to string, so are more widely used.  Variants can also have attributes, which flattened strings cannot.  However, LabVIEW classes and dynamic dispatch often provide a better solution, since they do not require any data conversion and are infinitely customizable.

 

Let us know if you have further questions.

Message 2 of 10
(7,193 Views)

[quote]

If a LabVIEW variant knows its own data type, why must you specify a data type in the Variant to Data function? Why can the variant not just unflatten itself? This is by design rather than by necessity. Variants must fit within the existing LabVIEW paradigm, namely that the data type of every wire is defined at design time. If a variant unflattened itself, what color would the wire be? While it is understandable that LabVIEW does not allow a variant to unflatten itself, LabVIEW needs a function that returns the data type of the variant as an enumerated type, similar to the VarType function in Visual Basic. Without any way to check data types before attempting a conversion, the only recourse is to guess an acceptable data type and then check for an error when the conversion fails.

[/quote]

 

http://www.ni.com/white-paper/4998/en/

 

Variant to Data still faster than Flatten to String (3x Approximatelly), cause no data conversion is required. 

 

 

 Flatten to string: Labview make an entire data structure copy and reallocate to conversion in single memory block. 

 Variant to Data&colon; Labview just allocate pointer to memory allocation that actually carries the data.

 

With Small datatypes, that performance doesn't make any difference,but it's important to understand this concepts.

 

PS: Sry for bad english. I'm brazilian. 😄

Message 3 of 10
(7,192 Views)

The document says that I can Variant data types also store meta data with them.

 

Suppose I have a waveform in 1D DBL array and want to store the some meta data like Sampling Rate, Bit depth etc with it. How do I do that? 

0 Kudos
Message 4 of 10
(7,158 Views)
Solution
Accepted by topic author LVCoder

Use Set Variant Attribute Function.

 

That.png

 

 

 

Message 5 of 10
(7,155 Views)

Thanks!

0 Kudos
Message 6 of 10
(7,144 Views)

Hi

I created a while loop and the values should store in the decimal Array for each iteration. But the decimal array is not fetching any data but the read buffer is getting pls find the attachement

0 Kudos
Message 7 of 10
(6,923 Views)

In what way is this related to variant data, the topic of this thread?

0 Kudos
Message 8 of 10
(6,892 Views)

I donot know much about Labview, I have just seen String and put the query here

0 Kudos
Message 9 of 10
(6,860 Views)

Well, it is probably better to start a new thread with a completely unrelated question, especially if the current thread is already marked as solved. How are you now going to mark the solution to your question? You cannot!

 

... but looking at your code, you need to keep the 2D array in a shift register, else you start with a blank array with every new iteration.

What determines the loop rate? Make sure you don't run out of memory if you keep building a 2D array without upper limit.

If you want to see the array as it builds, the indicator belongs inside the loop, of course.

0 Kudos
Message 10 of 10
(6,850 Views)