Main Content

Dynamic memory allocation in MATLAB functions

Description

Use dynamic memory allocation (malloc) for variable-size arrays whose size (in bytes) is greater than or equal to the dynamic memory allocation threshold. This parameter applies to MATLAB® code in a MATLAB Function block, a Stateflow® chart, or a System object™ associated with a MATLAB System block. This parameter does not apply to:

  • Input or output signals

  • Parameters

  • Global variables

  • Discrete state properties of System objects associated with a MATLAB System block

Category: Simulation Target > Advanced parameters

Settings

Default: On (for GRT-based targets) | Off (for ERT-based targets)

On

Enables dynamic memory allocation.

Off

Disables dynamic memory allocation.

Dependency

Enables the Dynamic memory allocation threshold in MATLAB functions parameter.

Tips

  • Code that uses dynamic memory allocation can be less efficient than code that uses static memory allocation. Unless your model requires dynamic memory allocation, consider clearing this check box.

  • If sufficient memory is not available to satisfy a memory allocation request, dynamic memory allocation can fail. The code generator does not check memory allocation requirements. For safety-critical systems, the recommended setting for this parameter is Off.

Command-Line Information

Parameter: MATLABDynamicMemAlloc
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOff
Safety precautionOff

Related Topics