Javatpoint Logo
Javatpoint Logo

Difference between Virtual and Physical Address

The addresses identify a location in the memory where the actual code resides in the system in the operating system. We store the data in the memory at different locations with addresses to access the data again whenever required in the future. There are two types of addresses used for memory in the operating system, i.e., the physical address and logical address.

The logical address is a virtual address viewed by the user. The user can't view the physical address directly. The logical address is used as a reference to access the physical address. The fundamental difference between logical and physical addresses is that the CPU generates the logical address during program execution. In contrast, the physical address refers to a location in the memory unit.

What is a Logical Address?

A logical address is an address that is generated by the CPU during program execution. The logical address is a virtual address as it does not exist physically, and therefore, it is also known as a Virtual Address. This address is used as a reference to access the physical memory location by CPU. The term Logical Address Space is used to set all logical addresses generated from a program's perspective.

A logical address usually ranges from zero to maximum (max). The user program that generates the logical address assumes that the process runs on locations between 0 and max. This logical address (generated by CPU) combines with the base address generated by the MMU to form the physical address. The hardware device called Memory-Management Unit is used for mapping logical addresses to their corresponding physical address.

What is a Physical Address?

The physical address identifies the physical location of required data in memory. The user never directly deals with the physical address but can access it by its corresponding logical address. The user program generates the logical address and thinks it is running in it, but the program needs physical memory for its execution. Therefore, the logical address must be mapped to the physical address by MMU before they are used. The Physical Address Space is used for all physical addresses corresponding to the logical addresses in a logical address space.

Difference between Logical and Physical Address

The basic difference between Logical and physical addresses is that The CPU generates a logical address from a program's perspective. In contrast, the physical address is a location that exists in the memory unit. Logical Address Space is the set of all logical addresses generated by the CPU for a program. In contrast, all physical addresses mapped to corresponding logical addresses are called Physical Address Space. The logical address does not exist physically in the memory, whereas a physical address is a location in the memory that can be accessed physically.

Virtual vs Physical Address

Identical logical addresses are generated by Compile-time and Load time address binding methods, whereas they differ in the run-time address binding method. The CPU generates the logical address while the program is running, whereas the physical address is computed by the Memory Management Unit (MMU). There are some other differences between the logical and physical addresses, and let's discuss them with the help of the below comparison table.

Terms Logical Address Physical Address
Definition the CPU generates the logical address while the program is running The physical address is a location in memory.
Location The logical address does not exist physically in the memory, and therefore it is sometimes known as a virtual address. The physical address is a location in the memory unit.
Access The logical address is used as a reference to access the physical address. The physical address cannot be accessed directly.
Address space The set of all the logical addresses generated about a program by the CPU is called Logical Address Space. Whereas all the physical addresses mapped to the logical address is called Physical Address Space.

Mapping Virtual Addresses to Physical Addresses

Memory consists of large array addresses. It is the responsibility of the CPU to fetch the instruction address from the program counter. These instructions may cause loading or storage to a specific memory address.

Virtual vs Physical Address

Address binding is the process of mapping from one address space to another address space. Logical addresses are generated by the CPU during execution, whereas physical address refers to the location in a physical memory unit (the one loaded into memory). Note that users deal only with logical addresses. The MMU translates the logical address. The output of this process is the appropriate physical address of the data in RAM. An address binding can be done in three different ways:

  1. Compile Time: An absolute address can be generated if you know where a process will reside in memory at compile time. That is, a physical address is generated in the program executable during compilation. Loading such an executable into memory is very fast. But if another process occupies the generated address space, then the program crashes, and it becomes necessary to recompile the program to use virtual address space.
  2. Load Time: If it is not known at the compile time where the process will reside, then relocated addresses will be generated. The loader translates the relocated address to an absolute address. The base address of the process in the main memory is added to all logical addresses by the loader to generate the absolute address. If the base address of the process changes, then we need to reload the process again.
  3. Execution Time:The instructions are already loaded into memory and are processed by the CPU. Additional memory may be allocated or reallocated at this time. This process is used if the process can be moved from one memory to another during execution (dynamic linking done during load or run time). e.g., - Compaction.

What is Memory Management Unit (MMU)

The run-time mapping between the virtual and physical addresses is done by a hardware device known as MMU. The operating system will handle the processes and move the processes between disk and memory in memory management. It keeps track of available and used memory. The Memory Management Unit is a combination of these two registers,

  1. Base Register: It contains the starting physical address of the process.
  2. Limit Register: It mentions the limit relative to the base address on the region occupied by the process.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA