Building Malleable VIs

Build malleable VIs to perform the same operation on any acceptable data type instead of saving a separate copy of the VI for each data type. Malleable VIs are useful if an operation can be implemented in similar ways for different data types without significant customization for a specific data type. If the operation must be implemented differently across data types or if the sets of terminals differ across data types, build a polymorphic VI instead.

You can create a malleable VI in the following ways:

When you place a malleable VI on the block diagram, the inputs and outputs display the default data types. If you wire a control, indicator, or constant to an input or output, the input or output adapts to the wired data type.

For example, in the Sort 2D Array malleable VI, the 2D array input and the sorted 2D array output accept 2D arrays of any data type except refnums, with 2D array of variant as the default data type. If you wire a 2D array of string to 2D array, the data types of 2D array and sorted 2D array both change to 2D array of string. However, if you wire a 1D array to 2D array, the VI appears broken because this malleable VI is not implemented to accept 1D arrays.

You can build specialized malleable VIs for the following purposes using the Type Specialization structure and the Assert Type VIs and functions:

For example, the Sort 2D Array malleable VI uses the Type Specialization structure to behave differently when index is an integer versus an array of integers so that the malleable VI works in an expected way for both data types. The index input coerces integer types other than signed 32-bit integers to signed 32-bit integers. You can force index to accept signed 32-bit integers only using the Assert Integer Type VI.

Because malleable VIs are inherently polymorphic, they accept any data type that does not cause syntax errors. NI recommends that you allow coercion in your malleable VIs for better code reusability. Restrict the data types a malleable VI can accept only if your application meets one of the following conditions:

Related Information

Debugging Malleable VIs

Choosing between Malleable VIs and Polymorphic VIs