Lower Estimate of Size of Local Variables
Total size of local variables in function taking nested scopes into account
Description
This metric provides an optimistic estimate of the total size of local variables in a function. The metric is the sum of the following sizes in bytes:
Size of function return value
Sizes of function parameters
Sizes of local variables
Suppose that the function has variable definitions in nested scopes as follows:
The software computes the total variable size in each scope and uses whichever total is greatest. For instance, if a conditional statement has variable definitions, the software computes the total variable size in each branch, and then uses whichever total is greatest. If a nested scope itself has further nested scopes, the same process is repeated for the inner scopes.type func (type param_1, ...) { { /* Scope 1 */ type var_1, ...; } { /* Scope 2 */ type var_2, ...; } }
A variable defined in a nested scope is not visible outside the scope. Therefore, some compilers reuse stack space for variables defined in separate scopes. This metric provides a more accurate estimate of stack usage for such compilers. Otherwise, use the metric
Higher Estimate of Size of Local Variables
. This metric adds the size of all local variables, whether or not they are defined in nested scopes.Additional padding introduced for memory alignment
Your actual stack usage due to local variables can be different from the metric value.
Some of the variables are stored in registers instead of on the stack.
Your compiler performs variable liveness analysis to enable certain memory optimizations. When computing this metric, Polyspace® does not consider these optimizations.
Your compiler uses additional memory during a function call. For instance, compilers store the address to which the execution returns following the function call. When computing this metric, Polyspace does not consider this hidden memory usage.
Compilers optimize temporary variables in different ways. This metric excludes temporary variables. Only the variables that are explicitly declared by the user are considered.
However, the metric provides a reasonable estimate of the stack usage due to local variables.
When a function returns a class
, struct
, or
union
that has a copy constructor, the compiler might perform a return
value optimization. Instead of returning a class object, the function might use a pointer to
pass the value. This optimization might change the value of this metric.
To determine the sizes of basic types, the software uses your specifications for Target processor type (-target)
. The metric also takes
into account #pragma pack
directives in your code.
Examples
Metric Information
Group: Function |
Acronym:
LOCAL_VARS_MIN |
HIS Metric: No |
Version History
Introduced in R2016b