Fabian,

Agreed, obviously if you allocate something on a stack in a method you
can't expect the caller to be able to efficiently maintain that memory.

>class C {
>  S s;
>
>  public C() {
>    s = new S();
>  }
>}

>Now, on which stack is s supposed to live in an instance of C? It
>can't be allocated on the constructor's function stack, because it
>would be destroyed as soon as the constructor is left. Instead, the
>lifespan of s must be as long as that of the instance of C. One
>efficient way to achieve this is to allocate it directly within the
>memory for the C object.
>

There is only one stack (from a thread of execution point of view), a
function uses part of the stack that (if the code generator does it's job)
the caller is not affected by.  But, that't not to say a function can't
push something on the stack that the caller could pop.  I believe in .NET
this is illegal.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to