Memory Use
Description
This metric measures the stack memory consumed by the functions and other callable entities of your code.
Polyspace Implementation
When you calculate memory use, Polyspace® Test™ instruments your source code to calculate the number of calls to functions and stack memory consumption. Polyspace Test assumes that the stack memory required by a function is allocated during function entry. This assumption might not be true in cases where the stack memory is allocated at run time, such as when you use variable length arrays. Polyspace Test calculates the stack consumption of a called function by subtracting the position of the stack pointer during a function entry from the last known position of the stack pointer.
When calculating the stack memory required by a function, Polyspace Test calculates several different metrics:
Self— The amount of stack memory required by a function. Consider a functionfoo(). Assume that the position of the stack pointer is initially atSP0. Whenfoo()is called, the stack pointer moves toSP1. Then, Polyspace Test calculates theSelfvalue as:Self = SP1-SP0
Max— The maximum amount of stack memory required by a function. A function might require different amounts of stack memory along different execution paths. TheMaxvalue represents the maximum possible stack memory consumed by the different execution paths.Count— Represents the number of times a function executes. If thecountvalue of a function exceedsUINT_MAX, Polyspace sets thecountvalue toUINT_MAX.
Polyspace Test does not support calculating more than one of the code coverage, execution time, or memory use metrics at a time.
Examples
Tips
When reviewing stack profiling results, note that the reported memory use represents an upper limit of stack usage for your code. This is because the instrumentation process for stack profiling injects various macros into copies of your source code, which may create additional local objects and alter stack memory usage.
C and C++ source code is instrumented differently in order to accommodate the features of C++ that are absent in C. The calculated memory use of the same source code might increase slightly if you compile the code using a C++ compiler.
The memory use per function is calculated at function startup. If a function allocates some memory after startup, that part of the memory use might be reported on a child function (callee).
For instance, the function
PIController_Update_wrapper()works with a variable-length arrayintegral_state. The memory for the array is allocated after function startup and is therefore reported as memory use of the child functionPIController_Update().void PIController_Update_wrapper( const int N ) { float integral_state[N]; for(i=0;i<N;i++) { integral_state[i] = i; } PIController_Update(integral_state, N); }
Version History
Introduced in R2023b