04-04-2012 10:32 AM
I have a VI that a) holds state information specific to that VI, and b) performs specific functions. I want to now use that VI as multiple instances within my program. First I change it to be re-entrant, and then I change it to to pre-allocate memory so that it preserves state information.
As I understand it, EVERY time a reentrant VI is called a new clone is made. This is the crux of my problem. What I really want is to create just three or four of these clones and call them from different points in the program. Is there a way to reference individual clones without creating a new one every time?
Or should I just approach this from a different angle?
04-04-2012 10:38 AM
I think that you get a new clone for every node. So if you have a reentrant VI in a for loop that executes 1000 times, LabVIEW will only allocate one instance. If you place five copies of your VI on the BD you will get five instances. That is the way I understand it which may be incorrect. Also my understanding of your question may be incorrect
04-04-2012 11:57 AM
RGreg wrote:
I have a VI that a) holds state information specific to that VI, and b) performs specific functions. I want to now use that VI as multiple instances within my program. First I change it to be re-entrant, and then I change it to to pre-allocate memory so that it preserves state information.
As I understand it, EVERY time a reentrant VI is called a new clone is made. This is the crux of my problem. What I really want is to create just three or four of these clones and call them from different points in the program. Is there a way to reference individual clones without creating a new one every time?
Or should I just approach this from a different angle?
Just a slightly different angle.
A specific CLONE of a reenterant vi can be called by referance (ACBR) if the referance is created with both the 40 and 100 flags set. heres a snippet that uses my famous delay.vi which is Re-enterant pre-allocate. note mSec Count , mSec Count 2 & mSec Count 3 show they all exit at the same time. so they are all in parallel. mSec Count 6 and mSec Count 5 are also approximatly = and ran at the same time as the three calls to the vi. mSec Count 4 ran on the same instace on Delay.vi as mSec Count 4 since they share the same refnum in.
04-04-2012 12:13 PM
If the VI is simply used to store data and won't take long to execute, then it may be easiest to approach the problem slightly differently: maintain an array of data inside that VI, and reference only one item in the array at a time. If the operations on that data need to run in parallel, make the storage into a separate, non-reentrant VI, then put the operations in a reentrant VI that calls the non-reentrant storage function.
Another alternate approach is the use of a LabVIEW class (an object-oriented approach). Each instance will be a separate instance of the same class, the instance-specific data travels on a wire, and the operations can be reentrant.
There is a way to do it almost exactly as you describe, but it's a bit more complicated. Use VI Server to open several instances of the reentrant VI. Each instance gets its own data space. You can then call a specific instance by reference, and the data will stay with that instance.