减少数据副本
调整模型参数以提高代码执行速度并减少内存使用量
通过消除生成的代码中的数据副本,减少 RAM 和 ROM 消耗并提高代码执行速度。代码生成器会消除一些数据副本。通过调整某些模型参数设置、为 MATLAB Function 模块的输入和输出参量指定相同的名称,以及使用 Simulink 信号指定重用,您可以消除其他数据副本。
主题
减少数据副本(默认操作)
- 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. - 在生成的代码中重用全局模块输出
代码生成器尝试重用全局变量。 - 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. - 将数据副本转换为指针赋值
代码生成器通过尝试用指针赋值取代for
循环控制的元素赋值和memcpy
函数调用,来优化向量信号赋值的生成代码。 - 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 in Generated Code
For models containing a Bus Assignment block, if possible, the code generator uses the same variable for the block input and output.
减少数据副本(指定操作)
- 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
Remove data copies by using signal labels. - 优化全局变量使用
选择全局变量引用优化来满足您的内存使用量和执行速度要求。 - Specify Buffer Reuse for MATLAB Function Blocks in a Path
Reuse buffers across MATLAB Function blocks. - Specify Buffer Reuse for Signals in a Path
Use the Reusable storage class to specify buffer reuse for multiple signals in a path. - Generate Efficient Code for Bus Signals
Model buses to maximize efficiency of the generated code.