Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 6, 2006


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

LabVIEW Real-Time Memory Management

19 ratings | 3.89 out of 5
Print
When you reboot or reset your RT hardware, the real-time operating system and an embedded version of LabVIEW are loaded into memory.

[+] Enlarge Image
Figure 1. Memory usage after resetting or rebooting the RT Target.

As LabVIEW runs, it uses available memory for your compiled code and data. LabVIEW also allocates memory for arrays as they are built. All of the elements in the array need to be contiguous in memory, without any breaks. In Figure 2, A.vi creates Array 1.

[+] Enlarge Image
Figure 2. A.vi creates Array 1.

The same memory addresses can be reused if you stop a VI and then run it again with arrays the same size or smaller. In Figure 3, A.vi creates Array 2. Since Array 2 is smaller than Array 1, contiguous memory for Array 1 remains in the reserved memory space.

[+] Enlarge Image
Figure 3. A.vi creates Array 2 during its second run.

However, if we run the VI again with larger arrays, or run another program that generates larger arrays, embedded LabVIEW has to look to the previously unused locations in memory to find contiguous space, since the previously used locations are not large enough. In Figure 4, A.vi creates an array larger than the previous arrays, so new available memory is used.

[+] Enlarge Image
Figure 4. A.vi creates Array 3 during its third run.

Even when you stop the VI, embedded LabVIEW continues to run, so the memory that is reserved by VIs cannot be made available. In this example, if A.vi is run a fourth time and attempts to create an array larger than Array 3, the operation will fail. Even though there is enough memory to create the array, the memory is not contiguous.

Since Windows has access to large amounts of virtual memory, running out of memory in LabVIEW for Windows is a usually not a concern. On an RTOS, however, virtual memory is not used, since this would hinder determinism. Also, on Windows, restarting LabVIEW allows the memory it is using to be "wiped clean," but in the RTOS, embedded LabVIEW starts when the RT Target is reset and stops when you turn it off.

With this in mind, you should design your deterministic applications to be memory conscious. Always preallocate space for your arrays equal to the largest array size that you will encounter. In the above example, A.vi could preserve its memory space by preallocating array space equal in size to Array 3, since all other arrays it created would fit into that space.


19 ratings | 3.89 out of 5
Print

Reader Comments | Submit a comment »

 

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/).