Disable Dynamic Memory Allocation During Code Generation
To disable dynamic memory allocation using the MATLAB® Coder™ app:
To open the Generate dialog box, on the Generate Code page, click the Generate arrow .
Click More Settings.
On the Memory tab, under Variable Sizing Support, set Dynamic memory allocation to
To disable dynamic memory allocation at the command line:
In the MATLAB workspace, define the configuration object:
DynamicMemoryAllocationproperty of the configuration object to
cfg.DynamicMemoryAllocation = 'Off';
If a variable-size array in the MATLAB code does not have a maximum upper bound, disabling dynamic memory allocation leads to a code generation error. Therefore, you can identify variable-size arrays in your MATLAB code that do not have a maximum upper bound. These arrays are the arrays that are dynamically allocated in the generated code.
- Minimize Dynamic Memory Allocation
- Provide Maximum Size for Variable-Size Arrays
- Set Dynamic Memory Allocation Threshold