Link to home
Start Free TrialLog in
Avatar of william007
william007

asked on

Heap and Stack

What is heap and stack? and what is their relationship?
I am new to this, and hope someone can recommend some introductory URLs that clearly introduce this, thanks:-)
SOLUTION
Avatar of giltjr
giltjr
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of william007
william007

ASKER

Hi, do you mean that the thing store in heap will stay there as long as it can be unless you remove them explicitly; and for the thing store stack will be remove automatically once you access it?
Correct.

Another description from: http://blogs.wwwcoder.com/govinda/archive/2004/08/16/688.aspx

Stack and Heap:
Both of 'em are sources from which memory is allocated. Stack is automatic, which is created when memory is in scope, and destroyed when it is out of scope. Heap is manual and created and destroyed when requested. On stack, the local variables (unless they are static or register data members), function parameters are stored on stack. On heap normally global variables, static local variables, any data allocated by using calls like new, malloc, calloc etc. memory allocation calls.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
William, if you're after an abstract definition of a stack & heap, then please ignore this post.. But if you have a particular context, then perhaps we can provide a simpler and more suitable definition ...

(e.g., the "Java Heap").
Thanks for all the reply:-)

InteractiveMind,  I would like to hear about the definition in Java context.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So, how about Java Stack? Is it only use for recursive call?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, InteractiveMind,

Thanks, this gave me a more "concrete" view of heap and stack.
My last question is,
1)Is this practise apply to C++ and VB also?
2)How the Non Object Oriented language(like C etc) make use of heap?
I'm afraid that my understanding of lower-level programming is limited, so I could not give you a definite answer.
[Stack's as data types are certainly used in C, C++, and VB though]

Sorry
Thanks:-)
--> 1)Is this practise apply to C++ and VB also?

Assuming you are talking about stack processing, yes, all languages that make use of stacks are processed LIFO.


--> 2)How the Non Object Oriented language(like C etc) make use of heap?

These are used to store your variables or varaible that may be needed by the system.

See:

     http://www.cprogramming.com/tutorial.html

for more information.
--> 1)Is this practise apply to C++ and VB also?
Are they using heap to store object, and static variable those kind of things also?