减少数据副本
调整模型参数以提高代码执行速度并减少内存使用量
通过消除生成的代码中的数据副本,减少 RAM 和 ROM 消耗并提高代码执行速度。代码生成器会消除一些数据副本。通过调整某些模型参数设置、为 MATLAB Function 模块的输入和输出参量指定相同的名称,以及使用 Simulink 信号指定重用,您可以消除其他数据副本。
模型设置
主题
减少数据副本基础知识
- Design Techniques to Optimize Models for Efficient Code Generation
Apply design tools and techniques to optimize a model for code generation. - Optimize Generated Code Using Code Efficiency Tools and Techniques
When generating production code from your model to deploy into a real-time embedded system, code efficiency is an important consideration. - Configure Model for Code Generation Objectives by Using Code Generation Advisor
Use the Code Generation Advisor to check your model against code generation objectives. - Generate Efficient Code by Setting Model Configuration Parameters
Choose the efficiency level and priorities for your generated code.
减少数据副本(默认操作)
- 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. - 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.
减少数据副本(指定操作)
- 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.