Building Malleable VIs
- Updated2025-08-15
- 3 minute(s) read
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:
- To create a new, blank malleable VI, select File»New and select Malleable VI from the New dialog box.
- To convert an existing VI into a malleable VI, set the file extension to
.vim. If the existing VI is not configured to be
inlined
into its calling VIs, the malleable VI appears broken. You must configure the malleable VI to be inlined by selecting
File»VI Properties»Execution, enabling the
Inline subVI into calling VIs
and
Preallocated clone reentrant execution
options, and disabling the
Allow debugging
and
Enable automatic error handling
options. Note You can convert only standard VIs into malleable VIs. You cannot convert polymorphic VIs, global VIs, or XControl abilities into malleable VIs.
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:
- Customizing sections of code in a malleable VI for specific data types
- Forcing a malleable VI to accept only a subset of the acceptable data types
- Forcing a malleable VI to decline specific data types
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:
- Coercion causes significant performance burden.
- Specific data types in the context of the application are meaningless.