By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,106 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

Explain this

P: n/a

This is an interview question asked in Robo.
How the memory address moves in Heap and stack?
That I knew it, Heap upper to lower and in stack lower to upper.

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?
What is the diamond problem in C++?
Data structure used to implement snake and ladder game?


Aug 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> This is an interview question asked in Robo.
How the memory address moves in Heap and stack?
That I knew it, Heap upper to lower and in stack lower to upper.


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.
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?


This would be best answered in a newsgroup of the relavant platform.
What is the diamond problem in C++?


Diamond inheritance.

class Base_Class {
// ...
};

class Derived_L : public Base_Class {
// ...
};

class Derived_R : public Base_Class {
// ...
};

class Most_Derived : public Derived_L, public Derived_R {
// ...
};

In the inheritance heirarchy given above, the "Most_Derived" class
would have 2 copies of the "Base_Class". This is overcome by virtual
inheritance from Base_Class.

class Derived_L : virtual public Base_Class {
// ...
};

class Derived_R : virtual public Base_Class {
// ...
};

Srini

Aug 17 '05 #2

P: n/a
Thanks for your replay. Really it great to know some thing more about
my problems.

But I am still not clear why is so question . Can any one make it more
clear .

Aug 17 '05 #3

P: n/a
> Thanks for your replay. Really it great to know some thing more about
my problems.

But I am still not clear why is so question . Can any one make it more
clear .


It is probably caused by operating systems that do not have virtual memory
management.
You can have the heap start at the bottom of memory and the stack at the
top. When those two meet, then you are out of memory.
If they would grow in the same direction, you would have to preallocate an
amount of memory for each and one of them would run out of memory before all
memory had been used.

Niels Dybdahl
Aug 17 '05 #4

P: n/a

Srini wrote:
This is an interview question asked in Robo.
How the memory address moves in Heap and stack?


That I knew it, Heap upper to lower and in stack lower to upper.


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.


I think a better, and more portable answer would have been "They
usually grow in opposite directions".
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?


This would be best answered in a newsgroup of the relavant platform.


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

Aug 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.