Manage Memory in LabVIEW Using a New Block Diagram Structure
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
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 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.
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
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.
Learn More About LabVIEW 8.5
To learn more about new features and changes in LabVIEW 8.5, visit the LabVIEW 8.5 web portal at ni.com.
Launch LabVIEW online to use the latest features.
Related Links
LabVIEW Help: In Place Element Structure
Manuals: LabVIEW 8.5 Upgrade Notes
Reader Comments | Submit a comment »
From my test code, memory control does NOT
show improvement of speed with array.
- c.j.wang@coodtec.com - Jun 5, 2008
So is it only useful to modify data that will
not increase or decrease the size of the
data involved? This is a more generic
question to the one above on string
concatenation.
- simon.cheng@advmeas.com - Mar 25, 2008
What if...
What happens if you try to concatenate a
string within the structure? Will the
compiler ignore the "in placeness" and
allocate memory anyway? Please clarify if
there are problems that could arise.
- Nov 8, 2007
Incorrect example Fig 1
Figure 1 is intended to show replacing
an array element back into the same
location in the array, and the text
describes using replace array subset,
BUT it uses the insert into array function.
Poor checking!
- Aug 7, 2007
Error in this page?
It says "When you run the above VI, LabVIEW
makes a new copy of the array and stores the
copy in memory." I'm pretty sure the LabVIEW
compiler avoids the ARRAY copy and just makes
an ELEMENT copy, right? Also, the first block
diagram is really sloppy for a piece of
example code.
- Aug 4, 2007
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).

