Você está na página 1de 3

1/3 www.ni.

com
1.
2.
3.
4.
5.
Manage Memory in LabVIEW Using a New Block Diagram Structure
Publish Date: Jan 10, 2011
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
Using the In Place Element Structure to Increase Efficiency
Getting Started with the In Place Element Structure
When to Use the In Place Element Structure
Learn More About LabVIEW
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.
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 and inputs of the function. When you run the above VI, LabVIEW makes a array index
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.
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 palette by navigating to 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 ProgrammingApplication ControlMemory Control
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
2/3 www.ni.com
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
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 , , and and an array of the Name Birthday Occupation
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 , , and so on even though you are not operating on those Name Birthday
fields.
3/3 www.ni.com
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 element and speed up your operation. An increase in speed does not happen in every application, but the In Name
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.
4. Learn More About LabVIEW
To learn more about features and changes in LabVIEW, visit . What's New in LabVIEW

Launch to use the latest features. LabVIEW online
5. Related Links
LabVIEW Help: In Place Element Structure
Manuals: LabVIEW 8.5 Upgrade Notes

Você também pode gostar