labviewpre-allocation

Does preallocate clone only allocate one clone if a VI is in a FOR loop?


I'm going through the sample exam papers in advance of sitting the CLD-R.

I came across the reentrancy question shown below:

enter image description here

The answer is 4.

There is no specific mention of preallocation in a for loop in the documentation.

The "preallocating" means that for every call, we create a data space and clone for that call.

The above suggests the answer would be 6, there are six calls in total but the answer is 4. Does this mean that only one clone is assigned for a VI in a FOR loop?


Solution

  • Does this mean that only one clone is assigned for a VI in a FOR loop?

    Yes. The relevant term is "call site" and in the help you can find this:

    In reentrant execution, LabVIEW allocates multiple instances, or clones, of the data space so that each call site, or usage of the subVI on the block diagram of the caller, can execute simultaneously, in parallel, such that each call site uses a separate clone.

    Since the VI is in a single place in the code, it gets reused. This becomes very relevant when you write a VI which has useful state (like a feedback node) and then later you naively call it in a loop expecting each iteration of the loop to have its own copy with its own state, only to find that all the iterations share the same state.