Re: Explain this
Srini wrote:[color=blue][color=green]
> > This is an interview question asked in Robo.
> >[color=darkred]
> > >How the memory address moves in Heap and stack?[/color]
> >
> > That I knew it, Heap upper to lower and in stack lower to upper.
> >[/color]
>
> This is not correct. It depends on the platform. For example, on a
> HP-UX (PA-RISC architecture) stack grows lower address to higher
> address while on Intel x86 platforms the stack grows from higher to
> lower addresses.[/color]
I think a better, and more portable answer would have been "They
usually grow in opposite directions".
[color=blue][color=green]
> > Then the next quotation was why?
> >
> > (I need answer to this question)
> > I told them that, this is because sack keep on growing and the latest
> > record must be retrieved so it is like that. But I don't think it is
> > the right answer to that question. Can any one tell me the answer to
> > this question?[/color]
>
> This would be best answered in a newsgroup of the relavant platform.[/color]
Since the stack is a contiguous, growable area of memory and the heap
uses non-contiguous allocation of memory in blocks, it is important to
keep the heap allocations as far away from the stack for as long as
possible, just to stay out of its way. Having its stack encroach upon
the memory of one of its allocated blocks, is a fatal error for an
executing program.
Greg |