addresses pointed by pointers are logical or physical?

Please someone answer this question

Recommended Answers

All 3 Replies

Read this wiki.

Basically, any pointers in a program is "logical" (or virtual), never physical (unless you are not running under an operating system). Managing the memory allocated for processes is a job for the OS (i.e. the OS manages where memory is allocated to store the executable code for the running processes, the memory used by processes (stack and heap), the same for kernel processes). The OS needs the freedom to decide what should be in RAM (because it is needed a lot), what is paged to files, how to arrange memory blocks, etc. etc. To do all this in a way that goes completely unnoticed by processes (the values of the pointers don't change), it has to create a layer of memory mappings that map the pointers that a process has to their actual physical location. Realizing that mapping is a very complex system (with process-sharing, caching and synchronization issues). But, certainly, the pointers that a program holds are indeed virtual addresses, the proof is simple: they don't change even as the process memory is relocated. Another indication of that is also the fact that if you access memory that isn't allocated to the current process, you get a "segmentation fault" or "access violation" error from the OS, this occurs while the address mapping is done and if the virtual address is not in the process' virtual address space.

yep as told by mike.
The user program never sees the real physical address.
The program create a pointer to location created by CPU(called virtual or logical address), store it in memory, manipulate it and compare it with other addresses.
The memory mapping hardware converts logical addresses to physical address.

logical address range 0 to max.
physical address range R+0 to R+max.

The user program generates only logical addresses and thinks that the process runs in location 0 to max.However these logical address must be mapped to physical address before they are used.

It might be logical, it might be physical. Depends on the hardware and how it is configured. If the processor has no memory remapping capability (i.e. no MMU) then you ONLY have physical addresses. Ancient home computers (before 80286) had no MMU (memory management unit). The first commonly used desktop computer that had a good MMU was the 80386. Even on an 80386, addresses might be logical or physical depending on whether you enabled "paging" (enabled the MMU). Even with paging enabled, if your page tables mapped the logical addresses to the same physical address, pointers would be both logical and physical (there would be no distinction). If your page tables mapped memory in such a way that logical addresses don't map to the same physical address, then there would be a difference.

For example, if you were writing a driver for a piece of hardware, you would need an awareness of physical addresses. Your piece of hardware might have some memory that can be mapped so it is accessible by the CPU. Say you knew somehow that the memory is mapped to physical address X. In a typical operating system, you could make a system call to request access to that physical address. The operating system would map some range of logical addresses to that physical addresses. In your driver code, you would have a pointer to the logical address, and the MMU hardware would map it to the physical address expected by the hardware.

I suppose you could make a generalization that pointers are always logical addresses. Whether they are also physical or not depends on if the mapping from logical to physical changes the address.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.