内存使用量
减少生成的 C/C++ 代码使用的 RAM、ROM 和堆栈空间
确定如何修改您的 MATLAB® 代码,以减少所生成代码的内存使用量。调用函数时,通过对输入和输出使用相同的变量来控制数据的传递方式。按引用传递可以减少所生成代码的内存使用量。通过设置堆栈空间使用量限制以及指定何时使用动态内存分配来控制如何分配内存。通过禁用生成附加代码的功能(例如,对整数溢出的支持)使代码大小最小化。
有关如何针对特定条件优化代码的详细信息,请参阅优化策略。
函数
coder.areUnboundedVariableSizedArraysSupported | Check if current configuration settings allow unbounded variable-size arrays (自 R2024a 起) |
coder.ceval | 从生成的代码中调用 C/C++ 函数 |
coder.const | 在生成的代码中将表达式折叠为常量 |
coder.inline | 控制生成代码中当前函数的内联 |
coder.inlineCall | Inline called function in generated code (自 R2024a 起) |
coder.nonInlineCall | Prevent inlining of called function in generated code (自 R2024a 起) |
类
coder.Constant | Specification of constant value for code generation |
coder.ExternalDependency | Interface to external code |
主题
生成代码优化
- 优化策略
优化所生成的代码的执行速度或内存使用量。 - Stack Allocation and Performance
Allocate large variables on the heap when you have limited stack space. - MATLAB Coder 对生成代码进行优化
代码生成器使用优化来提高生成代码的性能。
条件语句
- Prevent Code Generation for Unused Execution Paths
Make a control-flow variable constant to prevent code generation of unused branches. - Excluding Unused Paths from Generated Code
Make the control-flow variable constant to prevent generation of code for unused branches.
函数调用
- Avoid Data Copies of Function Inputs in Generated Code
Generate code that passes input arguments by reference. - 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. - Control Stack Space Usage
Specify the maximum stack space that the generated code can use. - 将函数调用折叠为常量
通过在生成的代码中用常量替换表达式来减少执行时间。
数组
- 设置动态内存分配阈值
对小于特定大小的数组禁用动态内存分配。 - Reuse Large Arrays and Structures
Specify variable reuse to reduce memory usage. - Code Generation for Sparse Matrices
Use sparse matrices in MATLAB code intended for code generation.
数值边缘情形
- Disable Support for Integer Overflow or Nonfinites
Improve performance by suppressing generation of supporting code to handle integer overflow or nonfinites.
自定义代码集成
- Integrate External/Custom Code
Improve performance by integrating your own optimized code. - Optimize Generated Code for Fast Fourier Transform Functions
Choose the correct fast Fourier transform implementation for your workflow and target hardware. - Speed Up Linear Algebra in Generated Standalone Code by Using LAPACK Calls
Generate LAPACK calls for certain linear algebra functions. Specify LAPACK library to use. - Speed Up Matrix Operations in Generated Standalone Code by Using BLAS Calls
Generate BLAS calls for certain low-level matrix operations. Specify BLAS library to use. - Speed Up Fast Fourier Transforms in Generated Standalone Code by Using FFTW Library Calls
Generate FFTW library calls for fast Fourier transforms. Specify the FFTW library.