Differences Between Reentrant VIs (Preallocate), Reentrant VIs (Share Clones), VI Templates, and Dynamic VIsHardware: PXI/CompactPCI>>Controllers
Problem: When do I use reentrant VIs, Template VIs and Dynamically called VIs? Solution: Reentrant VIs - Used when you want to run several instances of the same VI simultaneously. When the VI is not reentrant there is one data space for the VI. Therefore only one caller at a time can be running the VI and so a caller may have to "wait its turn" to use the VI. This is the default option for a VI, but you can set a VI to be reentrant under File»VI Properties»Execution. In LabVIEW 8.5, the option of sharing a clone or preallocating was introduced. ![]() Reentrant VIs (Share Clones) - If the option to share clones between instances is selected, the VI has a pool of data spaces (same thing as a pool of clones). Initially only two clones are created when the calling VI begins. A caller will use one of these data spaces, but it doesn't know which one, and it may be a different instance on subsequent calls. When there are not enough data spaces (clones) in the pool for the number of simultaneous callers, new data spaces (clones) are created and added to the pool. Here the word "sharing" from "share clones between instances" means that the data spaces can be used by multiple callers over time. If there are 20 calls to the subVI, but those calls happen such that at most 2 calls are going on at the same time, the pool will have only 2 data spaces in it and they will be "shared" among the 20 calls. Since only the necessary number of clones is created according to the current need, memory use is optimized. Reentrant VIs (Preallocate)- If you use the preallocate clone for each instance option, each caller is given its own private data space (and clone). If there are 20 calls to the VI, 20 clones will be created and added to the pool when the calling VI begins. It may be that only 2 are ever busy at the same time if the calling pattern is like the one described above. If it is important that every call to a given instance of the subVI use the same clone (for example, if the subVI nees to hold data from call to call) then use this type of reentrant VI. Shared clones would not work because you would never know which instance of the subVI last used the clone you are about to use, and the stored information would "cross talk" unpredictably between the subVIs. The "preallocating" means that for every call, we create a data space and clone for that call. The preallocation happens before the VI runs. If you want to open multiple front panels of the same VI, reentrant SubVI options will not help.To open multiple instances of a VI, you have two options: If the VI you want to open multiple times is a top-level VI, you can duplicate the top-level VI on disk to a temp directory with a unique name and open the new file instance. It is not necessary to duplicate any subVIs, only the top-level VI. You can then use the VI Server to open and run the copies. Template VIs - You can make a multi-instance panel into a template VI. Then open the file each time from the template. VI templates are VIs with the .vit extension. You can create a new VI from a template under File»New»Start from template . This creates a new instance of the VI, with its own memory space. Dynamic VIs - You can open both VIs and VI templates with VI Server. VI server is used to dynamically load and run a VI. With subVIs, the code and the data space of the subVI are loaded when the top-level VI is loaded. When you dynamically load a VI, instead of using it as a subVI, its code will not be loaded until the subVI is called by the VI server. This saves memory and startup time. Related Links: KnowledgeBase 2YO91OHM: Why Do I Get Error 1126 when Opening a VI Dynamically with LabVIEW SubPanels? LabVIEW 8.5 Help: Capabilities of the VI Server LabVIEW 8.5 Help: Creating Template VIs LabVIEW 8.5 Help: Execution Properties Page Attachments:
Report Date: 10/21/2002 Last Updated: 08/21/2009 Document ID: 2QKDG7DW |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

