How does an optimizing c++ compiler determine when a stack slot of a function(part of stack frame of a function) is no longer needed by that function, so it can reuse its memory? .
By stack slot I mean a part of stack frame of a function, not necessarily a whole stack frame of a function and an example to clarify the matter is, suppose we have a function that has six integer variables defined in its scope, when it's time to use sixth variable in the function, fifth variable's become useless so compiler can use same memory block for fifth and sixth variables.
any information on this subject is appreciated.
Garrett2011
0
Light Poster
Recommended Answers
Jump to PostTypically it doesn't, unless you force it to. For example:
> g++44 -Wall -std=c++98 -pedantic -Werror -fomit-frame-pointer -fstrict-aliasing -fconserve-stack -fno-defer-pop
The frame of a function is transient, and the memory is reclaimed as soon as the function returns. It could also cause most debuggers to stumble.
All 3 Replies
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
vijayan121
1,152
Posting Virtuoso
Garrett2011
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.