Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 17th, 2005, 06:45 AM
kolari
Guest
 
Posts: n/a
Default Explain this


This is an interview question asked in Robo.
[color=blue]
>How the memory address moves in Heap and stack?[/color]

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

  #2  
Old August 17th, 2005, 07:05 AM
Srini
Guest
 
Posts: n/a
Default Re: Explain this

> This is an interview question asked in Robo.[color=blue]
>[color=green]
> >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=blue]
> 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=blue][color=green]
> >What is the diamond problem in C++?[/color][/color]

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

  #3  
Old August 17th, 2005, 07:25 AM
kolari
Guest
 
Posts: n/a
Default Re: Explain this

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 .

  #4  
Old August 17th, 2005, 08:05 AM
Niels Dybdahl
Guest
 
Posts: n/a
Default Re: Explain this

> Thanks for your replay. Really it great to know some thing more about[color=blue]
> my problems.
>
> But I am still not clear why is so question . Can any one make it more
> clear .[/color]

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


  #5  
Old August 18th, 2005, 01:15 AM
Greg
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles