Memory Usage

Reduce RAM, ROM, and stack space used by generated C/C++ code

Before you take steps to improve code generation, read about your options in 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.CodeConfig codegen configuration object
coder.ExternalDependency Interface to external code

Examples and How To

Conditional Statements

Prevent Code Generation for Unused Execution Paths

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

Function Calls

Eliminate Redundant Copies of Function Inputs

Use the same variable as a function input and output.

Inline Code

Inlining eliminates the overhead of a function call by replacing the function call with the body of the function.

Control Inlining

Restrict inlining to reduce the size of generated code and memory usage.

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.

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.

Concepts

Optimization Strategies

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.

MATLAB Coder Optimizations in Generated Code

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.

Was this topic helpful?