Configure Multi-Instance Code Generation
By default, for top models, the code generator produces code that is not reentrant.
Entry-point functions have a void-void interface. Code communicates with
other code by sharing access to global data structures that reside in shared memory.
For applications that can benefit from code reuse and require that each use or instance of the code maintains its own unique data, configure a model such that the code generator produces reentrant, multi-instantiable code. Multiple programs can use reentrant code simultaneously. When you configure a model for reentrancy, the execution (step) entry-point function uses root-level input and output arguments instead of global data structures.
Configure a Top Model for Multi-Instance Code Generation
Set model configuration parameter Code interface packaging to
Reusable function.
Apply additional diagnostic and code generation control by setting these model configuration parameters:
To select the severity level for diagnostic messages that the code generator displays when a model does not meet requirements for multi-instance code, set parameter Multi-instance code error diagnostic to
None,Warning, orError.To control how the generated code passes root-level model input and output to the reusable execution (step) function (requires Embedded Coder), set parameter Pass root-level I/O as to
Individual arguments,Structure reference, orPart of model data structure.To include a function in the generated file
that usesmodel.cmallocto dynamically allocate memory for model data structures (requires Embedded Coder), set parameter Use dynamic memory allocation for model initialization toOn.
For more information, see Generate Reentrant Code from Top Models (Embedded Coder).
Configure a Referenced Model for Multi-Instance Code Generation
Set model configuration parameter Total number of instances allowed per top
model to Multiple. With this parameter
setting, a model can be referenced more than once in a model hierarchy, if it contains
not constructs that preclude multiple references. An error occurs if the model cannot be
referenced multiple times, even if only one reference exists.
For more information, see Generate Reentrant Code from Simulink Function Blocks (Embedded Coder).