• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Heap and Stack in memory

 
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do Heap and stack pre exist in memory ? By that I mean , is it organized in hardware by the memory chip manufacturer ?
Is there exclusive allocation of physical memory space called heap and stack available in memory or is it created by the OS when a java program runs ?
Is heap and stack created by JVM or by the OS ?
Do all the languages (.net, java, Perl, C++ etc) use heap and stack for storing of variables and objects ?

http://www.maxi-pedia.com/what+is+heap+and+stack, on this link, its stated that memory is organized in three segments. (1)code (2)heap (3)stack.
This leads me to think that, its pre existing in the memory. Its provided by the manufacturer that way.

I am trying to find answers by reading articles, but can not get clarity on this.

Thanks.
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Main memory does not have this kind of segments physically... These segments are all virtual and created by the OS for the process...

OS plays a vital role in memory management. Process makes use of system calls of OS to have variables allocated either in stack and heap...

C, C++ and Java utilizes this memory segments...
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nirjari patel wrote:Do Heap and stack pre exist in memory ? By that I mean , is it organized in hardware by the memory chip manufacturer ?
Is there exclusive allocation of physical memory space called heap and stack available in memory or is it created by the OS when a java program runs ?
Is heap and stack created by JVM or by the OS ?
Do all the languages (.net, java, Perl, C++ etc) use heap and stack for storing of variables and objects ?

http://www.maxi-pedia.com/what+is+heap+and+stack, on this link, its stated that memory is organized in three segments. (1)code (2)heap (3)stack.
This leads me to think that, its pre existing in the memory. Its provided by the manufacturer that way.

I am trying to find answers by reading articles, but can not get clarity on this.

Thanks.



It is not clear from your post that you understand the definitions of heap and stack, so let me babble about that a minute.

Stack: when one method calls another, there are things that need to be saved as context from the calling routine, and space that is needed for local variables in the called routine. All that occupies an amount of space that varies with the method being called, and it stays active in memory (i.e., its values are significant) until the called routine returns. If the called routine calls another routine, another section of stack (sometimes called a stack frame) is allocated for that call, etc. All the implementations of this I've seen involve a contiguous area of memory, where one stack frame is placed immediately above or below the previous one.

Heap: when a program allocates memory for its own purposes, i.e., when it is going to use memory for some purpose other than a declared variable (and sometimes even then!), the memory for that comes from the heap. Most of the space in a Java heap is occupied with the memory containing the values within objects, along with pointers to them, etc.

A main difference between these two: Stack is allocated when a subprogram call is made and deallocated when that subprogram call returns. Heap is allocated when the program asks for it and deallocated according to the language being run; in the case of Java, heap space is recovered during "garbage collection", which is beyond the scope of this post.

So, on to your questions: this could be implemented in many ways. Another responder stated that the allocation, etc., was done by the operating system, but the Java implementations of this I've seen don't do it that way -- the JVM, when invoked, gets a big (BIG) block of memory when it starts up and manages stack and heap within that by itself, no OS calls unless it decides to increase the overall amount of memory it has.

You refer to the "manufacturer", which normally refers to hardware; the hardware people have very little to do with the implementation of stack and heap. They make machines that execute a set of instructions and change values in registers and memory according to those instructions, and interact with the outside world through I/O ports and such -- the languages you mention do use both heap and stack, but could implement them quite differently for each language, or even two implementations of the same language. So, usually, there is nothing in the hardware that dictates how heap and stack are implemented.

rc
 
Marshal
Posts: 80269
430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving thread as too difficult for "beginning Java™2
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic