Why is
Stack : Stored in Computer RAM like heap and
Heap : Stored in Computer RAM like stack ?
according to the nice answer by "Brain R Bondy" here
I am using Java language. Also what if i have too less RAM.
-
3Where should these things be stored otherwise?Thomas Jungblut– Thomas Jungblut2012年10月26日 09:16:48 +00:00Commented Oct 26, 2012 at 9:16
-
1No stack and heap are on RAM thats fine but stack like heap and heap like stack, what do you mean by that ?Rameshwar.S.Soni– Rameshwar.S.Soni2012年10月26日 09:18:28 +00:00Commented Oct 26, 2012 at 9:18
-
Have at look at these threads: stackoverflow.com/questions/362740/… and stackoverflow.com/questions/858250/…. Cheers,Anders R. Bystrup– Anders R. Bystrup2012年10月26日 09:19:21 +00:00Commented Oct 26, 2012 at 9:19
-
1I don't know what you mean by "stack like heap" that doesn't make sense and I don't see this statement in your linked answer.Thomas Jungblut– Thomas Jungblut2012年10月26日 09:21:41 +00:00Commented Oct 26, 2012 at 9:21
-
The link which i have provided has this answer, its second answer from top and has 370 up-votes---- The user name is Brain R BondyRameshwar.S.Soni– Rameshwar.S.Soni2012年10月26日 09:27:02 +00:00Commented Oct 26, 2012 at 9:27
3 Answers 3
Everything has to be stored in main memory (RAM) at some point, otherwise the CPU cannot work with it.
If you're running out of RAM, the operating system will outsource some of your application's memory to disk. This will make your program slow, but not break it. Because of this, the amount of memory your program can use does not depend on the amount of RAM that is physically available.
If you get stack overflow errors, you probably have an infinite recursion bug in your program.
If you get heap space/out of memory errors, see this question: What does Java option -Xmx stand for?
Comments
To let the processor access them as fast as possible, because they are used a lot.
Comments
This means only, that they are both kept in the RAM.