1

Not sure if heap or stack is just in a Java, but why have two separate things to hold memory? Why not just have an unlimited stack, or just have a an unlimited heap? What’s the purpose of having them separate, or the reasoning to design it like that? I think I understand the difference between the two at a beginner level.

Viroha
  • 11
  • 1
  • 1
    [What and where are the stack and heap?](https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap) – akuzminykh Jul 21 '20 at 06:51
  • 2
    Without a heap: What is your suggestion to share objects between any two different stackframes? – akuzminykh Jul 21 '20 at 06:53
  • @akuzminykh Or between two threads? Each thread has its own stack, whereas the heap is shared between all threads. Maybe this was what you meant. – Ole V.V. Jul 21 '20 at 10:11
  • @OleV.V. Both examples show that a heap is damn useful. :) I meant: If function `A` calls `B` and `x` is created in `B`, how do you use `x` in `C` where `C` is a call that happens after the call to `B`? – akuzminykh Jul 21 '20 at 16:12
  • @OleV.V. Of course with `x` being an object and not a primitive data type or a reference. – akuzminykh Jul 21 '20 at 16:23
  • 1
    @akuzminykh Your point is good, and thanks for explaining. In my head I began designing a JVM that should be able to that. Allow me to say that my design got hopeless very, very quickly! – Ole V.V. Jul 21 '20 at 19:28

0 Answers0