Array Size Restrictions for Code Generation
For code generation, the maximum number of elements of an array is constrained by the code generator and the target hardware.
For fixed-size arrays and variable-size arrays that use static memory allocation, the maximum number of elements is the smaller of:
intmax('int32')
.The largest integer that fits in the C
int
data type on the target hardware.
For variable-size arrays that use dynamic memory allocation, the maximum number of elements is the smaller of:
intmax('int32')
.The largest power of 2 that fits in the C
int
data type on the target hardware.
These restrictions apply even on a 64-bit platform.
For a fixed-size array, if the number of elements exceeds the maximum, the code generator reports an error at compile time.
For a variable-size array, if the number of elements exceeds the maximum at run time, the error checking behavior depends on the code generation target:
While running the code generated by using the
codegen
(MATLAB Coder) command, thefiaccel
(Fixed-Point Designer) command, or the MATLAB® Coder™ app, if run-time error checks are enabled, the generated code reports an error. By default, run-time error checks are enabled for MEX code and disabled for standalone C/C++ code.During simulation of a MATLAB Function block, the software reports an error. Generated standalone code for MATLAB Function blocks cannot report array size violations.