Are these kinds of analysis for effective use of stack frame memoryslots possible ?

G

Good Guy

I know a compiler may detect life-time of different variables of a
function and use the same stack frame slot for some different
variables if it detects at beginning of life-time of each one of them
life-time of previous variables has ended; but in case of local
objects of classes in a function may it analyze life-time of members
individually and say like since at this point life-time of this
specific data member is finished let's use this part of stack frame
memory for something else or it just does this for whole object as an
atomic entity, what about objects of unions, would there be such
analysis for those?
 
G

Good Guy

As far as the observable behavior remains the same, the compiler can do
about everything, including reusing portions of alive objects for other
purposes. However, I doubt any existing compiler actually does this. It
would be quite surprising to see during debgging that random bytes inside
the object change value for no apparent reason!

In any case, the compiler must be quite smart to figure out if it can
apply such an optimization, and the potential gain, if any, is very
small.


For understanding which parts of a union are currently not in use the
compiler has to be even more smarter.

Cheers
Paavo

I think myself this thing would be violating some C++ standard rule
that I don't know exactly what that would be and I believe the way
compiler looks at any object of any class or union it sees it as an
atomic thing though I still wonder if such optimization in terms of
efficient use of memory space would be possible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top