12-11-2023 05:16 PM
Hello,
I have a logic with recursion involving 2 subVIs (say A and B)
Will setting them both pre-allocated reentrant good Or should one of them be declared as shared clone and the other pre-allocated reentrant?
Thanks,
12-11-2023 06:41 PM
12-11-2023 09:04 PM
Please describe your "logic with recursion". In other words, what (exactly) are you trying to compute? Asking such vague questions that you've been posing on the Forum are quite unusual ...
Bob Schor
12-11-2023 10:31 PM
Hi Bob,
These vague questions are the ones which have perplexed me during CLA-R exam.
There is not much info with them.
12-12-2023 09:04 AM
@raphschru wrote:
Any VI that can call itself or that can be called by one of its subVIs is recursive and must be reentrant with shared clones, because the number of needed clones is not known in advance.
Real question here b/c curious.
My thinking is that recursion often (usually?) involves maintaining internal state in the higher level clone as it "calls itself" as a lower level clone. Thus, I'd expect that shared clones could lead to real trouble.
On the other hand, I don't think I have a good working theory for how preallocated clones can properly deal with the "unknown number" issue.
I toyed with a little recursion once upon a time, but mainly just for kicks. I think that back at that time, I only *ever* chose preallocated clones (or perhaps it was before the shared clone option even existed?). But the details are lost to the fog of time.
Anyone already have a MWE to demonstrate the right choice and show the pitfalls of the wrong one?
-Kevin P
12-12-2023 09:53 AM - edited 12-12-2023 09:59 AM
Class member clones are required to be shared, and I know for sure they work fine for multiple (unknown number) levels of reentrancy.
If you put a 'normal' (no class member) pre-allocated reentrant VI in its own call chain, at any level, you get an error:
If it's shared reentrant, it works fine.
This is rather simple to try...
You can however make the top level VI preallocated, and the 2nd level shared. Because the 2nd is shared, it breaks the problem and the main is not broken.
So, the answer AFAIK is shared reentrancy.
12-12-2023 10:02 AM
@Kevin_Price wrote:
My thinking is that recursion often (usually?) involves maintaining internal state in the higher level clone as it "calls itself" as a lower level clone. Thus, I'd expect that shared clones could lead to real trouble.
On the other hand, I don't think I have a good working theory for how preallocated clones can properly deal with the "unknown number" issue.
Yes, it's quite important to keep the data at a higher level (or sent in as a parameter) to allow the code to be shared.
12-12-2023 10:14 AM
@Kevin_Price wrote:On the other hand, I don't think I have a good working theory for how preallocated clones can properly deal with the "unknown number" issue.
Quite simplistically I think.
The code executes. When it calls a subVI, if it's a clone it allocates dataspace for a pre-allocated clone or re-uses dataspace for a shared clone if one is available. Repeat until done.
12-12-2023 10:16 AM
Might be helpful- there's some good discussion in this thread.
12-12-2023 10:23 AM
@BertMcMahan wrote:
Might be helpful- there's some good discussion in this thread.
That's funny.