LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reentrancy with a subVI inside itself

Solved!
Go to solution

As pointed out, replacing recursion with a stack often makes it easier to understand, but even if you stick with recursion, you might be reinventing the wheel. There are at least two popular tools which take clusters and convert them to strings - the MGI read/write anything VIs and the OpenG variant VIs (specifically, the variant config VIs). You might be able to use them and get away with it.

 

You can also flatten some data structures directly to JSON using the JSON primitives.


___________________
Try to take over the world!
0 Kudos
Message 11 of 15
(1,158 Views)

@nathand wrote:
 but I wouldn't recommend writing a lot of recursive LabVIEW code.

I've used recursion quite a lot.  It works particulary well with dynamic-dispatch methods in LVOOP.   

0 Kudos
Message 12 of 15
(1,125 Views)

@nathand wrote:

LabVIEW does not do this, so recursive calls will use more memory and incur a performance penalty versus a loop.

 


Depends on the depth of the tree-like structures one is passing over.  Clusters and subclusters of up to five levels deep means five clones of the reentrant fuction, which can be endlessly reused.  The initial creation of those five has some overhead, after which the only overhead is the subVI call.

0 Kudos
Message 13 of 15
(1,122 Views)

@tst wrote:

There are at least two popular tools which take clusters and convert them to strings - the MGI read/write anything VIs and the OpenG variant VIs (specifically, the variant config VIs).


I got it working so I'm going to leave it as-is but thanks for mentioning these tools. Just downloaded both MGI and OpenG tools packages and I'm having a lot of fun browsing the new possibilities.

0 Kudos
Message 14 of 15
(1,109 Views)

Not sure if this is its actual name but I've always heard of it as While Loop Recursion.  Where instead of calling yourself in a truely recursive way, you just use a while loop that pushes and pulls things to process, and you keep going until there is no more things to process.

 

The typical example I use of this the native Recursive File List.vi in the Advanced File I/O palette.  It finds all files and folders in a folder, then if there are folders in that folder, it adds them to the list of folders to process, which may add more folders, and more folders, etc.  It could have been done with recursion but I think debugging that would be more difficult where here you can clearly see the stack of folders to be processed.

0 Kudos
Message 15 of 15
(1,066 Views)