内存使用情况
Determine how to modify your MATLAB®code so that the generated code uses less memory. When calling functions, control how data is passed by using the same variables for input and output. Passing by reference reduces the memory used in generated code. Control how memory is allocated by setting limits for stack space usage and by specifying when dynamic memory allocation is used. Minimize code size by disabling features that generate additional code, such as support for integer overflow.
有关如何在特定条件下优化代码的更多信息,请参见Optimization Strategies.
Functions
coder.inline |
Control inlining in generated code |
coder.const |
Fold expressions into constants in generated code |
CODER.CEVAL |
Call external C/C++ function |
Classes
coder.Constant |
Represent set containing one MATLAB value |
coder.external依赖性 |
Interface to external code |
Examples and How To
Function Calls
Eliminate Redundant Copies of Function Inputs
Use the same variable as a function input and output.
Inlining eliminates the overhead of a function call by replacing the function call with the body of the function.
Restrict inlining to reduce the size of generated code and memory 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.
Arrays
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.
Numerical Edge Cases
Disable Support for Integer Overflow or Non-Finites
Improve performance by suppressing generation of supporting code for integer overflow or non-finites.
Custom Code Integration
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 Fast Fourier Transforms in Generated Standalone Code by Using FFTW Library Calls
Generate FFTW library calls for fast Fourier transforms. Specify the FFTW library.
Concepts
Optimize the execution speed or memory usage of generated code.
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.
To improve the performance of generated code, the code generator uses optimizations.
Disable Support for Integer Overflow or Non-Finites
Improve performance by suppressing generation of supporting code for integer overflow or non-finites.
Code Generation for Sparse Matrices
Use sparse matrices in MATLAB code intended for code generation.