简体   繁体   English

RAM不仅包含变量,还包含正在运行的进程的程序存储器吗?

[英]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. 我在研究虚拟内存时有一个关于RAM的问题。 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? 当我们在微控制器中编译程序时,程序代码被烧入闪存,变量存储在RAM中,对吗? 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); 我的意思是,虚拟内存的目标不是与物理内存(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)? 实际上可以扩展物理内存,例如,如果某个进程需要位于RAM外部的下一个地址,它是否不会更改页面(放开当前内容并从虚拟内存中获取页面)? Having said that, does the RAM not only contains the variables but also the program memory of the process running? 话虽这么说,RAM不仅包含变量,而且还包含正在运行的进程的程序存储器吗?

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. 当程序未执行或从未被调用时,指令位于闪存中,但没有为变量分配空间。但是闪存中包含了告诉OS何时为程序变量分配内存的指令。该程序被执行。

Only when the program is executed,the OS copies the program instructions onto the RAM and then allocates memory for the variables. 仅当执行程序时,操作系统才会将程序指令复制到RAM中,然后为变量分配内存。

Hence,YES! 因此,是的! .The RAM contains ALL the program instructions and variables,but only during the execution of the process. RAM包含所有程序指令和变量,但仅在执行过程中。

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. RAM是CPU可以直接访问的唯一存储,因此根据定义,程序指令必须存储在此处。

Otherwise, the CPU wouldn't know what to do. 否则,CPU将不知道该怎么办。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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