10-20-2009 10:20 AM
Hi,
I have an array of clusters CONTROL (calling it as "top level cluster array") with one of the cluster elements being a cluster array (please see attached).
I plan to pass "Reference" of this top level cluster to different VIs (like add element VI, insert element VI, delete element VI etc) and access (add/modify delete) the elements in this array.
In my code, how do I typecast the Array Element (cluster) to the inner cluster (as shown in the figure) ?
I am using LV RT on PXI.
Solved! Go to Solution.
10-20-2009 10:43 AM
What exactly are you trying to do with the reference to that inner array? You already have the array as the brown wire just above.
Also, don't auto-index and wire to the N terminal of a loop simultaneously. This is redundant. Since you are auto-indexing, delete the Array Size and wiring to the N terminal.
10-20-2009 11:01 AM
Hello smercurio_fc,
Thanks for a quick response. I will update my diagram as per your suggestion of removing the wire to the N terminal.
With respect to your first question: I want to add cluster elements in to the referenced array (outer most cluster).
Trying to add or modify elements using the using the value property does not update the referenced array. Please see the attached block diagram below.
10-20-2009 12:59 PM
If you want to add/modify elements of the inner array then you do not need a reference to do this. What you need are shift registers and some array functions. See attached for an example on replacing one of the elements of the inner array for one of the elements of the outer array.
You did not indicate which version of LabVIEW you have, so I assumed 8.5.
10-20-2009 01:04 PM
10-20-2009 02:47 PM
Hello Mark,
I have created a typedef of the control and am creating an instance in a VI at the top of the hirarchy.
Now my major problem is that I cannot typecast it as it gives me a class conflict whenever I try to use it as the target class.
Is there an example which shows how to typecast the Array element to its target ?
10-20-2009 03:06 PM
Hello smercurio_fc,
Thanks for your example ! Just one question: Effectively by putting shift registers, is the example creating a local copy of the complete array ? Even if the value of the lowest level cluster is modified, is the complete array is updated at the end (shift register value of the complete array at the right end is updated using the reference and property node) ? Will this VI be sluggish when the array size becomes big ?
Kindly comment.
10-20-2009 08:57 PM
There will be a buffer allocation at the shift register. Instead of auto-indexing you can wire to the N terminal and use an Index Array inside the outer loop. See attached picture. You will have an allocation for a single element of the array inside the loop, but the shift register will reuse the array buffer.
Tip: You can use the Tools -> Profile -> Show Buffer Allocations menu item to display where LabVIEW allocates buffers.
10-21-2009 09:01 AM
Hello smercurio_fc,
Thanks for all the help. Also the Buffer viewer is of very much help..
I can see that the buffer gets allocated for the complete array, effectively if the array gets bigger my VI is going to be very sluggish!
Is there a way in which I could pass the references to the inner clusters of the array and update them (like the way done in C/C++) ?
Also creating local copies of the complete array will generate race conditions if I am updating a different element at the same time in a different VI. I would prefer blocking one of the elements in the array (using sync mechanisms) and update it.
And this was the reason why I was trying to use the reference method as my initial approach.
Please do let me know as to how I can typecast an array element to the inner cluster (as per Mark's suggestion) and if that is correct.
Once again thanks for all the help! Pardon my ignorance to Labview as I am a newbee to this..
10-21-2009 09:16 AM
You cannot use references in the same way that you use pointers around in C. LabVIEW does not manage memory in the same way that C does. This is actually a good thing, though C programmers find it "cumbersome" or "restrictive". I have also programmed in C, and frankly I prefer LabVIEW's memory management any day of the week.
You had not initially mentioned that this was going to be done in multiple places at (potentially) the same time. Given that, my recommendation is to look into using Action Engines. They provide a means of basically providing a one-location acccess for your data. By using a single VI to access/modify your data you preclude the generation of race conditions. You may also want to join this with the concept of using variants to provide a means to quickly find your data rather than looping to find the element you're interested in. This technique has been around for a while and it has been discussed before. There are examples floating around. Will need to check to find one.
As for your question regarding using the reference method which you tried to employ in your initial approach, that's simply not going to gain you anything. You will still be creating buffers when you try to access the cluster elements. But you already have this information in the array inside the outer for loop, so you're just creating unnecessary extra programming for yourself.