Main Content

Data Copy Reduction

Adjust model parameters to improve code execution speed and reduce memory usage

Reduce RAM and ROM consumption and increase code execution speed by eliminating data copies in the generated code. The code generator eliminates some data copies. You can eliminate other data copies by adjusting certain model parameter settings, specifying the same name for the input and output arguments of MATLAB Function blocks, and by using Simulink signals to specify reuse.

Topics

Data Copy Reduction by Default

Optimize Generated Code By Passing Reusable Subsystem Outputs as Individual Arguments

The code generator eliminates data copies from local variables back to global block I/O structures by passing reusable subsystem outputs as individual arguments instead of as a pointer to a structure stored in global memory.

Minimize Computations and Storage for Intermediate Results at Block Outputs

The code generator folds block computations into a single expression, instead of generating separate code statements and storage declarations for each block in a model.

Reuse Global Block Outputs in the Generated Code

The code generator attempts to reuse global variables.

Enable and Reuse Local Block Outputs in Generated Code

Where possible, the code generator declares block outputs as local variables, so that it can potentially reuse these variables.

Convert Data Copies to Pointer Assignments

The code generator optimizes generated code for vector signal assignments by trying to replace for loop controlled element assignments and memcpy function calls with pointer assignments.

Virtualized Output Ports Optimization

The code generator eliminates code and data storage associated with root output ports by storing the signal entering the root output port as a global variable.

Inline Invariant Signals

Use the numerical values of invariant signals instead of their symbolic names in the generated code.

Data Copy Reduction for Data Store Read and Data Store Write Blocks

The code generator attempts to eliminate data copies for Data Store Read and Data Store Write blocks.

Reduce Data Copies for Bus Assignment Blocks

For models containing a Bus Assignment block, if possible, the code generator uses the same variable for the block input and output.

Data Copy Reduction by Specification

Remove Data Copies by Reordering Block Operations in the Generated Code

Reorder block operations in the generated code to eliminate temporary variables and associated data copies.

Optimize Generated Code by Using Signal Labels to Guide Buffer Reuse

If your model has the optimal parameter settings for removing data copies, you might be able to remove additional data copies by using signal labels.

Optimize Global Variable Usage

Choose a global variable reference optimization to satisfy your memory usage and execution speed requirements.

Specify Buffer Reuse for MATLAB Function Blocks in a Path

Reuse buffers across MATLAB Function blocks.

Specify Buffer Reuse by Using Simulink.Signal Objects

Use a Simulink signal object to specify buffer reuse for multiple signals in a path that may include root inport and outport ports, Delay blocks, and Unit Delay blocks.

Generate Efficient Code for Bus Signals

Model buses to maximize efficiency of the generated code.