Do the Stack and Heap both exist within your systems RAM?

别说谁变了你拦得住时间么 提交于 2020-01-05 12:12:12

问题


The question is pretty much the same as the title, do the Stack and Heap exist within the RAM at all times? Assuming Windows is the OS of the machine in question.

Also, if the answer to the above question is yes, is it possible to tell the JVM to create a specific applications Stack and Heap in a different location, such as an external micro SD card? Or to just set the default Stack/Heap creation location to some location other than RAM?


回答1:


Well, they might not be in RAM at all times. The stack and heap are just data structures allocated in RAM. When your program is actually using the CPU, they both will exist (at least partially) in RAM. However, it is possible that the OS will swap out the pages that the stack and heap are on when the program is not running. Then part of (or all) of the stack and heap could be written to disk.

I would guess that you would not be able to tell the JVM to allocate those data structures any place else. I cannot picture a scenario where you would want to; it would be horrifically slow. I am sure they are allocated with malloc() or a system call and it is unlikely the JVM would have any conditional code for that type of allocation.



来源:https://stackoverflow.com/questions/25250808/do-the-stack-and-heap-both-exist-within-your-systems-ram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!