Manage Memory in LabVIEW Using a New Block Diagram Structure

Publish Date: Jan 10, 2011 | 16 Ratings | 3.06 out of 5 |  PDF

Overview

Many common National Instruments LabVIEW operations, such as operating on an element of an array and placing the resulting value back into the same array index, require LabVIEW to copy data values and maintain those values in memory. This increases memory usage.

With LabVIEW 8.5, you can use the In Place Element structure, a block diagram node, to efficiently access the elements inside of complicated data structures, such as operating on a data element within an array, cluster, variant, or waveform without requiring the LabVIEW compiler to copy data values and maintain those values in memory. The In Place Element structure operates on data elements in the same memory location and returns those elements to the same location in the array, cluster, variant, or waveform.

Table of Contents

  1. Using the In Place Element Structure to Increase Efficiency
  2. Getting Started with the In Place Element Structure
  3. When to Use the In Place Element Structure
  4. Learn More About LabVIEW
  5. Related Links

1. Using the In Place Element Structure to Increase Efficiency

The In Place Element structure can execute a variety of common LabVIEW operations more efficiently than traditional LabVIEW programming methods. Figure 1 shows a scenario in which you can use the In Place Element structure to improve the execution and memory efficiency of a VI.

Array No Inplace

Figure 1. This image depicts a simple situation where an array element is operated on and placed
back into the array in the same location.

In Figure 1, LabVIEW indexes an array of 32-bit unsigned integers, increments the third element of the array, and replaces the element in the same location of the array. To replace the new value in the same array, the Replace Array Subset function requires you to wire the array and array index values to the array and index inputs of the function. When you run the above VI, LabVIEW makes a new copy of the array and stores the copy in memory. You can use the In Place Element structure to avoid making extra copies of the array and index values, as shown in the following block diagram.

Figure 2. You can gain efficiency by replacing an array element
with the In Place Element structure.

In Figure 2, the Array Index/Replace Elements border node of the In Place Element structure indexes an array of 32-bit unsigned integers, increments the third element of the array, and replaces the element in the same location in the array, similar to the first example block diagram. However, in this instance, LabVIEW does not have to create or store extra copies of the array values in memory. The In Place Element structure requires you to replace each indexed element in the array with the node on the right side of the structure. Because the structure requires you to replace the array element and the LabVIEW compiler knows which element to replace, LabVIEW does not have to create or store extra copies of the array or array elements in memory.

Back to Top

2. Getting Started with the In Place Element Structure

Unlike other LabVIEW structures, the in Place Element Structure is not located on the Structures palette. Instead, you can find it on the Memory Control palette by navigating to Programming»Application Control»Memory Control on the Functions palette. From this palette, you can drag the In Place Element Structure to a block diagram. Figure 3 displays an empty In Place Element structure on the block diagram.

 

Figure 3. Empty In Place Element structure

The In Place Element structure uses nodes that are attached to the border of the In Place Element Structure to perform operations on data. You can right-click the border of the In Place Element Structure and select the appropriate border node for the operation you want to perform (Figure 4). Each border node consists of a terminal on the left and right side of the structure (Figure 5). Once you choose a node and wire an input (an array, cluster, variant, or waveform), you can select an element on the left side of the structure, operate on the element within the structure, and wire the resulting value to the right side of the structure to replace the value in the existing location (Figure 6).

 

 

Figure 4. Configuring the border node for array indexing

 

 

Figure 5. The resulting border nodes for array indexing

 

 

Figure 6. An In Place Element structure with an array wired into the border node

Back to Top

3. When to Use the In Place Element Structure

The obvious question you may have about the In Place Element structure is, “When should I use it?” As with any code optimization, it is usually best to wait until you know what the bottleneck of your system is before you start to optimize. When the array, cluster, or waveform element the structure accesses is simple (such as an I32 or DBL), the performance gain is small. However, in general, you can operate complicated data structures more efficiently with the In Place Element structure compared with traditional LabVIEW programming methods.

For example, take the scenario of an array of clusters, each used to describe a person. The cluster is composed of fields such as Name, Birthday, and Occupation and an array of the characteristics of the person. To perform an operation on a single field in every cluster, you can use the In Place Element structure and a For Loop (Figure 7). Without the In Place Element structure, LabVIEW would make a copy of the cluster each time the operation went through the For Loop. This entails also copying Name, Birthday, and so on even though you are not operating on those fields.

Figure 7. You can use a nested In Place Element structure with For Loops to efficiently
operate on extremely complex data types.

By using the In Place Element structure, you prevent LabVIEW from copying the Name element and speed up your operation. An increase in speed does not happen in every application, but the In Place Element structure is handy when you need to extract an element from a complex data type, modify it, and then put it back in the array.

Back to Top

4. Learn More About LabVIEW

To learn more about features and changes in LabVIEW, visit What's New in LabVIEW.

 

Launch LabVIEW online to use the latest features.

Back to Top

5. Related Links

LabVIEW Help: In Place Element Structure
Manuals: LabVIEW 8.5 Upgrade Notes

 

Back to Top

Language

Bookmark & Share

Ratings

Rate this document

Answered Your Question?
Yes No

Submit