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

Products

Related Links - Developer Zone

Related Links - Products and Services

Preallocating Arrays for Deterministic Loops

13 ratings | 4.15 out of 5
Print
When programming a deterministic, time-critical loop, avoid using any shared resources, including the memory manager, to reduce jitter. If you are using arrays in your loops, you can reduce jitter by preallocating all of your arrays before entering the loop.

Figure 1 shows an example of a method that induces jitter. Because the Build Array node inside the WHILE loop uses the memory manager, a shared resource, this example induces jitter, especially if there are parallel normal priority VIs running that also use the memory manager.

Figure 1. Bad Example: While loop using Build Array.



Figure 2 shows an example of a method that reduced jitter. Because the WHILE loop uses a Replace Array Subset node to create the output array, this example does not use the memory manager because the array has been preallocated.

Figure 2. Good Example: While loop using Replace Array Subset.



Look inside all of the subVIs that are inside of your time-critical loop to make sure that no memory management occurs inside of them. Even if you build an array with only one element in it, the memory manager still is used. You also need to preallocate an array with only one element.


13 ratings | 4.15 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/).