LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP class Singleton implementation

Hello all,

I am trying to implement a 'Singleton' class because I want multiple threads to be able to access the class data.  

I do have a scalablity concern regarding the class data.  Currently, the class data control (cluster) has four array elements.  I plan to use one  private (write) method .vi for each data element since I don't want to have to update all four arrays.  If I want to added other controls (numeric, boolean, array, etc.) to the class data control, I will have to create additional write methods and (at least) modify the read method.

Is there an easier way to scale this data?

I'm using LabVIEW 8.20.

Regards,
Mark
>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 1 of 6
(4,107 Views)
ttt
>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 2 of 6
(4,087 Views)
Could you give a better explanation what are you planing to do with a LVOOP "Singleton". Since LVOOP objects are by value using them for singletons (which I think is an greatly misused pattern at least in the C++ world), would be rather tricky. I would guess that you would be better served with an Action Engine of some sort (since they handle multithreading in a straight forward way, and are basically singletons). But I can't say if they are the best choice since I don't know what you're trying to do.

As for dealing with the inputs in LV8.5 (and maybe in 8.2) you can right click on the class in the project explorer and create vi's for data access. So creating individual accessors is pretty easier. You could also build your class data out of cluster type defs, so you can break the data into logic pieces (and have the accessors work on those pieces).

Matt W


Message 3 of 6
(4,079 Views)
This is a great forum post with some links to some design pattern documents for LVOOP, including the Singleton design pattern. Hope this helps!
Jarrod S.
National Instruments
Message 4 of 6
(4,071 Views)
[QUOTE] Could you give a better explanation what are you planing to do with a LVOOP "Singleton".

Currently, I have two parallel loops where I want to share data.  One loop is writing (modifying) the data and one loop is reading the data.  The data cluster consists of four arrays that will be shared.  All of this is no problem.  My concern is that when I add another control to the cluster, then I have to write additional private methods to modify and read that data.

-Mark
>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 5 of 6
(4,058 Views)
One new feature of LV8.5 was the ability to automatically create accessors for private class data, saving you time for a normally tedious task.

And if you implement a Singleton pattern along the lines of the Discussion Forum post I mentioned, adding data accessors is no more difficult for the by reference case than it is for the by value case.

Are all the arrays in your cluster the same type? If so, you could make your data a little more dynamic to facilitate on flexible accessor VI instead of one for each array. For instance, instead of a cluster of four arrays, you could have one 2D array, where each row represents one of the arrays. Then your accessor takes in the array index to get, and retrieves that row from the 2D array.

The downside there is that all of the rows have to be the same length, so the shorter arrays will get padded. To get around that, you could have an extra array in your private data that denotes length, with one element for each row. Then you take a subset of the array when passing it out. Or you could have a 1D array of clusters that contain one array in them. Then the arrays in the clusters don't have to be the same length as each other. This is a common way to handle this situation in LabVIEW in general.


Jarrod S.
National Instruments
0 Kudos
Message 6 of 6
(4,046 Views)