LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

shift register and local variable..which is more suitable??

hi...
i have a question regarding the shift register and local variable before i proceed my programming...
in the program, it have a case structure inside a while loop, which is true at the initial of the program, and i need to make this case become false at the next loop..
so, shift register or local variable is more suitable for this case??
which 1 have the shorten loop time??and more consistent in loop??
thanks for help....
0 Kudos
Message 1 of 20
(6,854 Views)
Hi wu,

always use a ShiftRegister. Always. (Ok: as often as possible!).
Try to avoid local variables. They hurt performance, dataflow, memory management.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 20
(6,849 Views)
ok...
thanks for your advice...

0 Kudos
Message 3 of 20
(6,845 Views)

In your case, a shift register is more suitable.  However, local variables do definitely have their uses.

"Use local variables to access front panel objects from more than one location in a single VI and pass data between block diagram nodes that you cannot connect with a wire.

With a local variable, you can write to or read from a control or indicator on the front panel. Writing to a local variable is similar to passing data to any other terminal. However, with a local variable you can write to it even if it is a control or read from it even if it is an indicator. In effect, with a local variable, you can access a front panel object as both an input and an output."

Message 4 of 20
(6,802 Views)
thanx for ur advise...
0 Kudos
Message 5 of 20
(6,780 Views)


wuliao23 wrote:
in the program, it have a case structure inside a while loop, which is true at the initial of the program, and i need to make this case become false at the next loop..

Maybe you don't need either. 😄
 
If you want a case to execute only for the first time after the start of the program, use the "first call" primitive from the synchronization palette. Check the online help to make sure it's what you want.


wuliao23 wrote:
which 1 have the shorten loop time??and more consistent in loop??

If you want consistent loop times, you're looking in the wrong place. This has nothing to do with local variables or shift registers. To make loop times consistent, use a timed loop or a wait statement that is sufficiently long so it is the only time limiting step for the iteration.


Message Edited by altenbach on 02-06-2008 10:14 PM
Message 6 of 20
(6,776 Views)
ok...
i will try the way u suggested...
thanks....
0 Kudos
Message 7 of 20
(6,764 Views)

I agree with TMC-NI, both local variables and shift registers each have useful function. It's not always appropriate to constrain yourself to a shift register, especially if that means you'll need more than one or two. That approach could lead to unnecessary wiring complexity that can inhibit debugging and maintenance. On the other hand, local variables do incur some overhead in terms of speed and storage. But modern PCs have so much performance this is seldom a serious problem (going RT on a micro controller is a counter example.). As TMC-NI mentions, local variables offer a level of flexibility and scope that shift registers do not and I agree with that also.

0 Kudos
Message 8 of 20
(3,246 Views)

@pbisson wrote:

 It's not always appropriate to constrain yourself to a shift register, especially if that means you'll need more than one or two. That approach could lead to unnecessary wiring complexity that can inhibit debugging and maintenance.  


You should try using a cluster in a single shift register.  As many data items as needed with only one wire.

0 Kudos
Message 9 of 20
(3,239 Views)

Yes, clusters are useful. But I'm doing maintenance on an app (which I didn't write) with half a dozen different shift registers. There's a UI event handler too and about a dozen events handled. The code is absolutely un-readable with all those through lines for the various events. Many of the shift registers deal with variables irrelevant to a particular event, so they're just wired through. What a mess.

 

Consolidating literally scores of data items into a single cluster is probably also not good practice. Plus, you've also got to un-bundle and re-bundle them at the point of use. This burns up lots of block diagram space.

 

Just bear in mind, a local variable is actually just a pointer to the original storage location (the control), so it's really only just a 32/64-bit address. In the case just described, using a few local variables, judiciously, really cleans up the block diagram and makes the code much easier to read, understand, and maintain. If there's a small storage and cpu-clicks penalty, I'll take it gladly.

0 Kudos
Message 10 of 20
(3,233 Views)