问题
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