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.
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.
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.
The code generator attempts to reuse global variables.
Where possible, the code generator declares block outputs as local variables, so that it can potentially reuse these variables.
The code generator optimizes generated code for vector signal assignments by trying to
for loop controlled element assignments and
memcpy function calls with pointer assignments.
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.
Use the numerical values of invariant signals instead of their symbolic names in the generated code.
The code generator attempts to eliminate data copies for Data Store Read and Data Store Write blocks.
For models containing a Bus Assignment block, if possible, the code generator uses the same variable for the block input and output.
Reorder block operations in the generated code to eliminate temporary variables and associated data copies.
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.
Choose a global variable reference optimization to satisfy your memory usage and execution speed requirements.
Reuse buffers across MATLAB Function blocks.
Use the Reusable storage class to specify buffer reuse for multiple signals in a path.
Model buses to maximize efficiency of the generated code.