简体   繁体   中英

Does the RAM not only contains the variables but also the program memory of the process running?

I have a question regarding the RAM while I was studying virtual memory. When we compile a program in microcontroller, the program code is burned in the flash memory and the variables are stored in the RAM, right? Is it the same in our desktops? I mean, is not the goal of the virtual memory is to coordinate with the physical memory (RAM); virtually to extend the physical memory like let's say if a process needs the next address which is located outside the RAM, will it not change the page (letting go of the present and getting the page from the virtual memory)? Having said that, does the RAM not only contains the variables but also the program memory of the process running?

When a program is not executing or is never called,the instructions are on the flash memory,but no space is allocated for the variables.But the flash memory contains the instructions of telling the OS about the memory to be allocated for the program's variables whenever the program is executed.

Only when the program is executed,the OS copies the program instructions onto the RAM and then allocates memory for the variables.

Hence,YES! .The RAM contains ALL the program instructions and variables,but only during the execution of the process.

Only if the memory required by a process for its variables is not found in contagious physical locations like for example 'an array of variables' , then Virtual Memory is implemented.

RAM is the only storage that is directly accessible by the CPU, so by definition, the program instructions must be stored there.

Otherwise, the CPU wouldn't know what to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM