Main Content

本页的翻译已过时。点击此处可查看最新英文版本。

内存使用量

减少生成的 C/C++ 代码使用的 RAM、ROM 和堆栈空间

确定如何修改您的 MATLAB® 代码,以减少所生成代码的内存使用量。调用函数时,通过对输入和输出使用相同的变量来控制数据的传递方式。通过引用进行传递可以减少所生成代码的内存使用量。通过设置堆栈空间使用量限制以及指定何时使用动态内存分配来控制如何分配内存。通过禁用生成附加代码的功能(例如,对整数溢出的支持)使代码大小最小化。

有关如何针对特定条件优化代码的详细信息,请参阅优化策略

函数

coder.inlineControl inlining of a specific function in generated code
coder.constFold expressions into constants in generated code
coder.ceval调用外部 C/C++ 函数

coder.ConstantSpecification of constant value for code generation
coder.ExternalDependencyInterface to external code

示例和操作指南

条件语句

Prevent Code Generation for Unused Execution Paths

Make a control-flow variable constant to prevent code generation of 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.

Fold Function Calls into Constants

Reduce execution time by replacing expression with constant in the generated code.

数组

Set Dynamic Memory Allocation Threshold

Disable dynamic memory allocation for arrays less than a certain size.

Reuse Large Arrays and Structures

Specify variable reuse to reduce memory usage.

数值边情形

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.

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.

概念

优化策略

优化所生成的代码的执行速度或内存使用量。

Excluding Unused Paths from Generated Code

Make the control-flow variable constant to prevent generation of code for unused branches.

Stack Allocation and Performance

Allocate large variables on the heap when you have limited stack space.

MATLAB Coder 对生成代码进行优化

代码生成器使用优化来提高生成代码的性能。

Disable Support for Integer Overflow or Nonfinites

Improve performance by suppressing generation of supporting code to handle integer overflow or nonfinites.

Code Generation for Sparse Matrices

Use sparse matrices in MATLAB code intended for code generation.