开发者

What does the memory address mean?

Does a hex memory address represent the position in the memory as a whole?

e.g. 4 gb ram and there is a memory adress. Does it point to the position(in bytes) that the data starts at? e.g. at 2.1 gb.

How do memory address work on hard disk before 开发者_Python百科the data is loaded into memory?

Is there ever a case where parts of the data are fetched from memory and other data is fetched from disk? How are the locations differentiated?

Thanks


A hex memory address (like what you would see if you printed out the value of a pointer) points to a location in virtual memory.

On a 32 bit system, each process has a full 4GB of virtual memory. This virtual memory is managed by the CPU and the operating system. When you access a location in virtual memory, the CPU and operating system determine where in the systems actual physical memory that location is mapped, and the data is retrieved from there.

The operating system may also take things out of physical memory and swap them to disk, in order to make room in physical memory for other things. Then, if you try to access the virtual memory location of something that was swapped from physical memory to disk, a "page fault" is generated which causes the OS to re-load the page from disk into physical memory.


Modern operating systems have virtual memory.

This means that the address which uses your program to access some byte in memory, is purely "virtual", non-existent. The operating system maps it via special hardware controllers to real memory locations which are completely different and there may be no physical memory location at all for a given address. For example, you may mmap() a file into (virtual) memory, and accessing a byte at the virtual addresses would mean accessing a byte of file. Similarly, if some memory page wasn't used for a long time, the OS may swap off the page from physical RAM to disk. In this case virtual memory wouldn't point to physical memory locations too.


In most cases - yes. But some processors uses 2 values to calculate real address. For example Intel 8086. Hardisk is only storage, that has its own system to store information. So before any CPU operation is executed, data has to be loaded into RAM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜