LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Local variable for an Array of fixed size

Hello,
 
I have a two multirate loops in a VI. 
In one loop, I want to refer an fixed sized array initialized in the other loop.
But I coudn't name the array, so I can't refer it.
Is there any way to refer it?
 
Thanks,
Young.
0 Kudos
Message 1 of 8
(5,585 Views)

Why can't you name it ? There is no other simple solution !

I suppose that you already right-clicked the indicator then selected visible item > label ?

Message Edité par chilly charly le 11-05-2005 06:00 AM

Chilly Charly    (aka CC)
0 Kudos
Message 2 of 8
(5,580 Views)
Hello,
 
Isn't that just showing the label of it? It just says "Initialize array."
Can I change that label and use (refer) it in another loop?
 
Thanks,
Young.
0 Kudos
Message 3 of 8
(5,570 Views)
Use the text tool and change the name to whatever you want. Or you could  also just leave it as it, right-click the indicator and choose "create local variable". The label IS the name.
Chilly Charly    (aka CC)
0 Kudos
Message 4 of 8
(5,566 Views)

1. For your method, I have to create an array control or indicator first. But once I create it, how can I make it a fixed sized? I thought the only way to make an array fixed sized is to use 'initialize array' VI. I used initialize array VI as a starting point (not with control or indicator). 

2. Anyway, I want an array to be (1) fixed sized, (2) and can be used as a local variable.

Could you give me any suggestion for this?

Thanks,

Young.

0 Kudos
Message 5 of 8
(5,562 Views)
If you need a local variable, there is no other way than to create an indicator for it.
In LabVIEW there is no "fixed length" array : you can always add or remove an array element, and you don't need to declare it as in other languages. They are intrinsic dynamic objcets. Of course, the memory manager has to cope with this, that's why it's often better to initialize an array, to give it its final size immediately, resulting in faster running programs. However, this is only noticeable with relatively large arrays (> 10000-100000 elements).
May be you should explain in more details what you intend to do, because trying to reproduce a C approach in LV is probably not the best thing to do. For instance, you said that you are initializing your array in a first loop. You mean that you re-initialize the array at each iteration ? 😮 I suppose no, so may be you could put the initialize step out of the loop, and wire the array to your two parallel loops.
Remember also that local variables are not always good programming solutions, since using them will generate copies of their content each time they are refered to. And that can low down your program very significantly...

Message Edité par chilly charly le 11-05-2005 05:05 PM

Chilly Charly    (aka CC)
0 Kudos
Message 6 of 8
(5,555 Views)
Thanks, your comment is very close to my concern.
Let me describe the task I'm implementing in detail: I have two loops of different update rate, which is a multirate program.
In one loop, which is update rate of 100 Hz (10 ms), updates an array of 12 elements.
In the other is a loop of update rate of 10 Hz (100 ms), but it's DAQ speed of 10000 samples/scan, so actually 1000 samples at a single update. Now after the single update, this DAQ loop needs the array of the other loop. Because both must be run continuously in run-time, the thru-put performance is important in my program - that's why I wanted to fix the size initially, but only update/replace the elements continously (Of course, the array is initialized outside the loop). And when I tried dynamically build or create it, I experienced performance degradation.
 
Actually, I'm thinking of a third loop, which is 1 ms of update rate, that uses both arrays of DAQ. So it's maybe about the shared memory issue. My questions are:
 
1. Can I just wire the arrays, and use it? If so, should I use it with Shift Register for each loop, or just loop tunnels?
2. Is LV's local variable theread-safe? What if I call an array when it's still being written by in another loop? I'm wondering if the local variable is similar to 'mutex' interface in C, or just a prepared copy of previous' update.
3. Any better way for my program?
 
Looking forward to your insight on LV programming...
Thanks,   - Young.
 
0 Kudos
Message 7 of 8
(5,545 Views)

I don't have to much time to analyze your problem right now, but I think you should be carefull with the local variable solution since there is no data dependency, ie no way to tell which value you are to retrieve. You should turn to queues (in the Advanced > Synchronization > Queues sub palette). Its probably the fastest solution to share data between parallel loops, and you additionnally you can decide how to retrieve the info.

See the attached example, where local and queue are compared.

Chilly Charly    (aka CC)
0 Kudos
Message 8 of 8
(5,540 Views)