Customize Stack Space Allocation
Your application might be constrained by limited memory. Controlling the maximum allowable size for the stack is one way to modify whether data is defined as local or global in the generated code. You can limit the use of stack space by specifying a positive integer value for theMaximum stack size (bytes)parameter, on theOptimizationpane of the Configuration parameter dialog box. Specifying the maximum allowable stack size provides control over the number of local and global variables in the generated code. Specifically, lowering the maximum stack size might generate more variables into global structures. The number of local and global variables help determine the required amount of stack space for execution of the generated code.
默认的洞穴ing forMaximum stack size (bytes)isInherit from target
. In this case, the value of the maximum stack size is the smaller value of the following: the default value set by the code generator (200,000 bytes) or the value of the TLC variableMaxStackSize
found in the system target file (ert.tlc
).
To specify a smaller stack size for your application, select theSpecify a value
option of theMaximum stack size (bytes)parameter and enter a positive integer value. To specify a smaller stack size at the command line, use:
set_param(model_name, 'MaxStackSize', 65000);
Note
For overall executable stack usage metrics, you might want to do a target-specific measurement, such as using runtime (empirical) analysis or static (code path) analysis with object code.
It is recommended that you use theMaximum stack size (bytes)parameter to control stack space allocation instead of modifying the TLC variable,MaxStackSize
, in the system target file. However, a target author might want to set the TLC variable,MaxStackSize
, for a target. To setMaxStackSize
, useassign
statements in the system target file (ert.tlc
), as in the following example.
%assign MaxStackSize = 4096
Write your%assign
statements in theConfigure RTW code generation settings
section of the system target file. The%assign
statement is described inTarget Language Compiler.