03-25-2013 01:26 PM
In my application I need to pass cluster to many different subVIs. What is the best practice for memory allocations.
Data cluster is of strict typedef
1. Pass the reference of the data cluster and use property node and varaint to data?
2. Pass the cluster to subVIs? This needs the data cluster as output terminal also if the data is modified.
When using show buffer allocation with both #1 and #2 the allocation seems to be same. What is the best practice to pass data cluster with many elements to subVis and have less memory allocation? Should the data cluster be of strict typedef or typedef, when to use typedef versus strict typedef?
The data cluster is also passed to different threads using queue(reference of data cluster is used).
Thanks.
03-25-2013 01:30 PM
Just pass the cluster data in. You will always be slower when using property nodes since those force a thread swap to the UI. Another alternative may be to use a Data Value Reference to pass a reference of the data around instead of the data itself. This is of course assuming you need everybody to use the same cluster data.
03-25-2013 01:37 PM
Generally we use to have FGV to read and write cluster data. You can read and write to the FGV in the sub vis so that you don't have any memory space used in any of the sub vi.
03-25-2013 01:50 PM
Thanks,to pass the data cluster is it better to pass only the elements required by a subVI or the complete cluster to subVIs?
Never used data value reference. Looks like if complete cluster is passed to all subVIs then data value reference can be used. Is the new data value reference to be created once at the start of application and then use this reference throuhout by unbundle and bundle functions?
03-25-2013 01:50 PM
How big is your clsuter? Do you really need to be worried about the memory usage? If you do you might want to use the DVR or FGV suggested earlier. If this is running on a PC and the cluster is not massive just pass it and don't worry about the memory copies. LabVIEW is pretty good at minimzing data copies.
03-25-2013 05:06 PM
Are there any example to look at for FGV to read and write values of cluster?
Cluster has arrays that grow dynamically until the application is stopped. Hence the cluster data can grow overtime.
Thanks.
03-25-2013 05:16 PM
Yes. I am glad to share Ben's Nugget which has the FGV concept inside.
03-25-2013 11:49 PM
thanks for the FGV concept. Can FGV be used to pass the data between different loops which are in diferent subVIs?
Main VI has producer-consumer and a parallel DAQ and parallel File VIs.
The cluster data is of complex type (array of cluster which contains more cluster and arrays).
The cluster data can be read and written from any of the threads or loops.
Reading FGV it seems to sequentially perform based on action. Can the FGV be used to send across loops which can write or read the data?
Thanks.
03-26-2013 12:21 AM - edited 03-26-2013 12:21 AM
Yes you can use it pass data between different loops but be sure about the flow when you use multiple writing otherwise it may endup in race condition.
03-26-2013 01:02 AM - edited 03-26-2013 01:03 AM
No one wants to answer your question about the typedef apparently. Strict typedef is no different then a type def except that the appearance remains the same. Most often, strict type def clusters are used for front panel controls; the programmer wants to force the way the typedef looks in the control editor to be the way it looks everywhere else in the program. From a programming standpoint, it is no different than a regular typedef. It's purely a visual thing.
You want to use a typedef or strict typedef when you want all instances of a control to update everywhere if a change is made. You're essentially defining a custom datatype. This is most often done with clusters because with clusters you may add or remove elements as your program changes. If you do this, would you want to go through every subVI updating the cluster! Nope. So you make a typedef and when you add or remove something from the typedef cluster, that change will be propogated everywhere throughout your program. Write one program without using typedefs, and you will quickly understand why they are important. Does that help clear it up?