C++/C++ Memory management
Expert: vijayan - 7/28/2009
QuestionHi vijayan ,
Can you plz tell me how the memory management will happen in C++ ?. we have stack,heap , code segement and data segment .. registers etc , In a C++ programm what are the variables,functions , vtables will store in these registers .
Can u plz tell me know if any good site is there on these?
Many thanks in advance
AnswerFunctions (code) is stored in a part of memory which is separate from that of variables (also called objects or data). On certain architectures, this area is called a code segment. For a programmer, this is largely uninteresting as the area of memory containing code can not be modified in any way at run time. All you can do is execute the code for the functions which are predetermined at the time you compile and link the code - functions can not be modified and new functions can not be created at run time.
As C++ programmers, we are interested in where our variables (objects) are stored, what is their life-time and so on. We can create objects at run time and can specify what their storage duration is. Where a variable is stored and the life time of the variable is determined my the storage duration of the variable. there are three storage durations supported by C++ : automatic, static and dynamic. Where v-tables are stored is implementation dependent, they would be in some part of the static data area.
I had answered a like question some time back, here is the link:
http://en.allexperts.com/q/C-1040/2008/8/different-variables-stored.htm
For more information, you could read the next few pages starting here:
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=28