04-27-2011 02:28 PM
Good afternoon
I have checked several post related to this question but I am still not sure what approach should I take.
The following example illustrates my question.
Suppose a Main.vi where the user inputs some parameters like "name" (str) and "value" (dbl).
Many subVIs of the Main program will use this parameters to perform their respective operations.
What is the optimal way to pass these parameters?
1) Bundle them and pass them to all subVIs by their connector pane.
Pro: Data flow is kept
Contra:Long wires to pass data to all subVis. Need of additional unbundle at each subVI. Not easily scalable.
2) Use a global variable
Pro: Scalable. No need of wiring/unbundling.
Contra:Need to add semaphores or alike to avoid race conditions. Update problems.
3) Use an Action Engine
Pro: Clear control of actions over the variable
Contra: Not easily scalable. Need of adding the AE subVI for each parameter.
4) Use single-element queue reference objects
This is at the moment my preferred option.
The final question is what would be the choise in case "value" is a huge array?
Thanks in advance!
Andres
04-27-2011 02:54 PM
You could also pass by queue or notifier.
For option #3, action engine would be one of the ways I'd lean. (Along with queue/notifier. I'd think about it a lot for any given situation I would have before deciding which is best.) However, you wouldn't necessarily need an action enginer for each parameter. I would make one action enginer that would have a get and set, along with an input that determines which to get and/or set. I'd let the action engine search through an array (the array might be an array of clusters that contains a name element and value element) and act on which ever element of the array that is desired.
04-27-2011 03:14 PM
@odiseo123 wrote:
Good afternoon
I have checked several post related to this question but I am still not sure what approach should I take.
The following example illustrates my question.
Suppose a Main.vi where the user inputs some parameters like "name" (str) and "value" (dbl).
Many subVIs of the Main program will use this parameters to perform their respective operations.
What is the optimal way to pass these parameters?
1) Bundle them and pass them to all subVIs by their connector pane.
Pro: Data flow is kept
Contra:Long wires to pass data to all subVis. Need of additional unbundle at each subVI. Not easily scalable.
2) Use a global variable
Pro: Scalable. No need of wiring/unbundling.
Contra:Need to add semaphores or alike to avoid race conditions. Update problems.
3) Use an Action Engine
Pro: Clear control of actions over the variable
Contra: Not easily scalable. Need of adding the AE subVI for each parameter.
4) Use single-element queue reference objects
This is at the moment my preferred option.
The final question is what would be the choise in case "value" is a huge array?
Thanks in advance!
Andres
I would recommend items 1, 3, and 4. I don't understand why you claim that a cluster or an AE are not scalable. The only reason I can think you have a porblem is that you are not using a typedef for your cluster. If you use a typedef for the cluster defintion (either as the cluster itself or the input/output of the AE) you have a very maintainable and scalable solution.
For a very large data item I would use a DVR (data value reference). This avoids any copies of data you may get if you use an AE. although an AE does minimize the number of data copies.
04-27-2011 03:40 PM
Option 1 has an issue with large data set in that you'll copy the data for every terminal you wire it to.
Option 2 is not very elegant and yes yo can ONLY set or get so no chance to act on the data
Option 3: The AE could be used to Get all, Get selected or get average .... of "data" and scales fairly well if you type def an ENUM with "Mode and wire that to a case selector. "Suppose a Main.vi where the user inputs some parameters like "name" (str) and "value" (dbl)." with this SPECIFIC application I would construct an AE that is updated by the user event and instantly available for all other consumers.. for very large data item I would use VIserver referances to the controls themselves! the AE only caries a U32 on the SR but you have access to the Value Property and can pick out the subset of interest or even process in the AE as a consumer to avoid copies
Option 4: If the queue is single element and your consumers Preview the queue you save a lot of data copies.
The biggest question is why do you need large data sets in multiple VIs? process large data to recover the intellegence in it immediatly and share the intellegence with the rest of the world
04-28-2011 03:50 AM
Thanks for the responses.
I usually develop this kind of applications, meaning, I present first a Menu-vi where I collect all the parameters of the program. Then subsequent SubVIs operate with the stored parameters. Until now I have mostly used global variables since is very easy to drop new variables when needed. Race conditions are avoided with semaphores but mainly by controlling data flow. However now I am concerned on the performance and unnecesary copies of data.
Thanks again for the suggestions.
Andres
04-28-2011 09:25 AM
If you are dropping globals and wrapping things with semaphores it sounds like it isn't that easy. Actually using wires to pass the data would be easier and avoid lots of the issues with globals. If you truly want to have a way to pass data around without as many wires I would recommend that you look at defining a LVOOP class. The class can use a DVR to keep a single copy of the data and provide a defined API for acting on that data.