Use Storage Classes in Reentrant, Multi-Instance Models and Components

The code that you generate from a model or component (referenced model or subsystem) is multi-instance code if it allows your application to maintain multiple independent instances of the component during execution. For example, you can generate reentrant, multi-instance code from an entire model by setting the model configuration parameter Code interface packaging to Reusable function. For general information about multi-instance models and components, see Code Reuse.

Under some circumstances, applying storage classes can:

  • Prevent you from generating multi-instance code.

  • Cause some data elements to appear in the generated code as singletons, which means that each instance of the model or component directly accesses the same shared, global data, creating dependencies between the instances.

To avoid errors and unexpected generation of single-instance code and singleton data, observe the guidelines and limitations below.

Directly Applied Storage Classes

When you apply a storage class directly to a data element (see Apply Storage Classes to Individual Signal, State, and Parameter Data Elements):

  • To generate multi-instance code, you must apply the storage class only to parameter objects, global data stores, shared local data stores, and root-level I/O.

  • The storage class yields only singleton data.

Storage Classes Applied by Default

When you apply a default storage class by using the Code Mapping Editor (see Configure Default Code Generation for Data (Embedded Coder)—requires Embedded Coder®):

  • For these data categories, you can generate only singleton data:

    • Model parameters

    • External parameter objects

    • Global data stores

    • Shared local data stores

  • For Internal data, you can generate only instance-specific data, which means each instance of the model or component operates on a separate copy of the data. For this category, you must use the example storage class SignalStruct, which appears after preparing a model for code generation with the Quick Start tool. Alternatively, you can create and use your own structured storage class by using an Embedded Coder Dictionary.

Related Topics