When possible, minimize dynamic memory allocation because it leads to slower execution of generated code. Dynamic memory allocation occurs when the code generator cannot find upper bounds for variable-size arrays.
If you know the maximum size of a variable-size array, you can avoid dynamic memory allocation. Follow these steps:
Depending on your requirements, do one of the following:
If a variable-size array in the MATLAB® code does not have a maximum size, disabling dynamic memory allocation leads to a code generation error. Before disabling dynamic memory allocation, you must provide a maximum size for variable-size arrays in your MATLAB code.