减少数据副本
调整模型参数以提高代码执行速度并减少内存使用量
通过消除生成的代码中的数据副本,减少 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
函数调用,来优化向量信号赋值的生成代码。 - 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. - 减少生成代码中 Bus Assignment 模块的数据副本
对于包含 Bus Assignment 模块的模型,如果可能,代码生成器会使用相同的变量作为模块的输入和输出。重用这些变量可以减少数据复制、节省 RAM 消耗并提高代码执行速度。
减少数据副本(指定操作)
- 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. - 优化全局变量使用
选择全局变量引用优化来满足您的内存使用量和执行速度要求。 - 为路径中的 MATLAB Function 模块指定缓冲区重用
在 MATLAB Function 模块中重用缓冲区。 - 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 Buses
Model buses to maximize efficiency of the generated code. - Control Inlining to Fine-Tune Performance and Readability of Generated Code
Inlining eliminates the overhead of function calls but can produce larger C/C++ code and reduce code readability.