Main Content

Maximum stack size (bytes)

Specify maximum stack size for local variables in model

Model Configuration Pane: Code Generation / Optimization


The Maximum stack size (bytes) parameter specifies the maximum size in bytes for local variables in the stack for your model. It does not limit the size of function arguments in the stack.


Inherit from target (default) | <Specify a value>
Inherit from target

The Simulink® Coder™ software assigns the maximum stack size to the smaller value of the following:

  • The default value (200,000 bytes) set by the Simulink Coder software

  • Value of the TLC variable MaxStackSize in the system target file

<Specify a value>

Specify a positive integer value. Simulink Coder software assigns the maximum stack size to the specified value.


If you specify a maximum stack size for a model, the estimated required stack size of a referenced model must be less than the specified maximum stack size of the parent model.


  • If you specify the maximum stack size to be zero, then the generated code implements all local variables as global data.

  • If you specify the maximum stack to be inf, then the generated code contains the least number of global variables.

  • If your model contains a variable that is larger than 4096 bytes, the code generator implements it in global memory by default. You can increase the size of variables that the code generator places in local memory by changing the value of the TLC variable MaxStackVariableSize. You can change this value by typing the following command in MATLAB Command Window:

Recommended Settings

DebuggingNo impact
TraceabilityNo impact
EfficiencyNo impact
Safety precautionNo impact

Programmatic Use

Parameter: MaxStackSize
Type: int
Value: valid value
Default: Inherit from target

Version History

Introduced in R2010a