This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Functional Global Avoid Making Multiple Copies of a Large Array in Memory

Updated Oct 4, 2019

Reported In

Software

  • LabVIEW Full

Issue Details

I have a large array of data and I want to be sure that I have only one copy of it in memory. I know that I can use a shift register and use the "Replace Array Subset" VI to keep a single copy. However, I need this to be a functional global. Since I can't initialize the shift register, I need a way to specify the type of array. If I use the "Initialize Array" VI within the loop, it creates another copy in memory.

To demonstrate the issue:
  1. Close all open VIs, but leave LabVIEW open.
  2. Create a new VI.
  3. Modify the Block Diagram to match the following images
  1. Open the Windows Task Manager and note the amount of memory that is being used by LabVIEW.
  2. Run the VI with the default settings and notice that the memory usage for LabVIEW increases by about 20 megabytes. The default setting for the dimension size results in an array of 1276900 double-precision numbers of 8 bytes each, which equals roughly 10 megabytes. Since there are two copies of the array, the memory usage increases by about 20 megabytes.
Alternatively, you can view the buffer allocations in LabVIEW by selecting Tools » Advanced » Show Buffer Allocations. You should see one allocation at the shift register and another at the "Initialize Array" VI.

Solution

It is possible to specify the array type using the "Reshape Array" VI instead of the "Initialize Array" VI. With this method, we are always working with the existing data and LabVIEW does not need to create a second array.

To see an example of this, try the following:
  1. Close all open VIs, but leave LabVIEW open.
  2. Create a new VI.
  3. Modify the Block Diagram to match the following images.

  1. Open the Windows Task Manager and note the amount of memory that is being used by LabVIEW.
  2. Run the VI with the default settings and notice that the memory usage for LabVIEW increases by about 10 megabytes. In this case, we are only working with one copy of the 10 megabyte array.
Alternatively, you can view the buffer allocations in LabVIEW by selecting Tools » Advanced » Show Buffer Allocations. You should only see one allocation at the shift register.