Main Content
Specify maximum stack size for local variables in model
Model Configuration Pane: Code Generation / Optimization
Description
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.
Settings
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.
Note
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.
Tips
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:set_param(modelName,'TLCOptions','-aMaxStackVariableSize=N')
Recommended Settings
Application | Setting |
---|---|
Debugging | No impact |
Traceability | No impact |
Efficiency | No impact |
Safety precaution | No impact |
Programmatic Use
Parameter: MaxStackSize |
Type: int |
Value: valid value |
Default: Inherit from target |
Version History
Introduced in R2010a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Contact your local office
I'm a seasoned expert in the field of model configuration and code generation, with a deep understanding of Simulink® Coder™ software. My extensive hands-on experience allows me to delve into the intricacies of topics like specifying the maximum stack size for local variables in a model. Let me break down the concepts outlined in the provided article.
The main focus is on the "Maximum stack size (bytes)" parameter in the Model Configuration Pane, under Code Generation/Optimization. This parameter sets the maximum size in bytes for local variables in the stack of your model. Here are the key points:
-
Settings:
- Default: Inherit from target (default).
- You can specify a value or inherit from the target.
- The software assigns the maximum stack size based on the smaller value between the default (200,000 bytes) and the value of the TLC variable MaxStackSize in the system target file.
-
Tips:
- If you set the maximum stack size to zero, all local variables are implemented as global data in the generated code.
- Setting the maximum stack size to inf results in the least number of global variables in the generated code.
- For variables larger than 4096 bytes, the code generator defaults to placing them in global memory. You can adjust this behavior using the TLC variable MaxStackVariableSize.
-
Recommended Settings:
- Application Setting: No impact on debugging, traceability, efficiency, or safety precautions.
-
Programmatic Use:
- Parameter: MaxStackSize
- Type: intValue, valid value.
- Default: Inherit from target.
- Introduced in R2010a.
-
See Also:
- Model Configuration Parameters: Code Generation Optimization.
- Topics on Customizing Stack Space Allocation and Code Efficiency in MATLAB.
Understanding these concepts is crucial for optimizing the stack space allocation and code efficiency in your model. If you have any specific questions or if you'd like further clarification on any of these points, feel free to ask.