"benben" <be******@hotmail.com> wrote in message
news:42***********************@news.optusnet.com.a u...
"TechCrazy" <Te*******@hotpop.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com... 1 int longFunction() {
2 string x1 ("eee");
3 string x2 = x1;
4 x2 = "fff";
....
More into detail:
After line 2, some memory m1 (of the size of sizeof(string)) is allocated
from the stack for x1; The object x1, during construction, might allocat
some memory M1 from elsewhere than the stack, most likely from the heap, of
size dependent on the implementation detail.
After line 3, some memory m2 (of the size of sizeof(string)) is allocated
from the stack for x2; Like wise, the object x2, during construction, might
allocat some memory M2 from elsewhere than the stack, most likely from the
heap, of size dependent on the implementation detail.
The memory blocks m1, M1, m2, M2 persist during the execution of subsequent
lines in the function.
When the objects run out of scope, i.e. when the function returns:
x2 is destroyed and m2 is freed. If "string" is a good implementation then
M2 is also freed during destruction of x2; then
x1 is destroyed and m1 is freed. Likewise M1 is also freed during
destruction of x1.
Regards,
Ben