Pooled Clause for the Add Program Command

Each time an MQL program object runs Tcl code and then exits out of Tcl mode, a Tcl interpreter is initialized, allocated, and then closed. During a session, you can execute several programs, and one program can call other programs, all of which require a Tcl interpreter and therefore the overhead of its use. In an effort to optimize multiple Tcl program execution, Tcl program objects can be specified as “pooled.”

Not used for Java Program Objects.

This page discusses:

Syntax

When such a program is first executed in a session, a pool of Tcl interpreters is initialized, one of which is allocated for the executing code. When the code is completed, the interpreter is freed up. Subsequent Tcl code that is executed in a pooled program during the session will use an interpreter from the already initialized pool.

When programs are created, the default is that they are not pooled. To define or modify an MQL type program to use the pool of interpreters, use the following syntax:

mql< > add|modify program PROG_NAME [!]pooled;

The “!” can be used to turn off the pooled setting of a program.

The number of interpreters available in a session is controlled by the MX_PROGRAM_POOL_SIZE setting in the initialization file (enovia.ini). MX_PROGRAM_POOL_SIZE sets the initial size of the Tcl interpreter pool. This setting is also used to extend the pool size when all the interpreters in the pool are allocated and another is requested. The default is 10.

Usage

Enabling the Tcl interpreter benefits MQL/Tcl programs that are nested or run in a loop, such as the trigger manager.

Unexpected results could occur if the pooled setting is turned on in a program without first reviewing and validating its code. Good programming techniques must be adhered to ensure proper results. When using an interpreter pool, Tcl variables are not cleared before freeing up an interpreter. This means that programs must explicitly set variables before using them, in case a previously executed program made use of the same variable name.

External, downloadable and Java programs do not use the Tcl interpreter pool, regardless of the setting in the program definition. In addition, MQL/Tcl programs that use the TK toolkit will not benefit from using the pooled setting, since user interaction is required. In fact, unexpected results, such as leaving a TK dialog displayed, might occur due to the use of variables as described above.

Before modifying existing programs to use the pooled setting, the code should be reviewed and validated. Only programs that include tcl code but no TK code should use the pooled setting.