What is Memory Mapping?

Memory mapping or mmap() is a function call in an Operating system like Unix. It is a low-level language, and it helps to directly map a file to the currently executing process’s own memory address space. Which could optimize File I/O operations, inter-process communication, etc.

Types of Mapping

1. File Mapping: It will map the File to the process virtual memory

  • Read-Only Mappings: The File is mapped into memory only for the purpose of reading. If we try to write it will end up in a segmentation fault.
  • Read-Write Mappings: The file is mapped into memory for both reading and writing. ie, it helps with file manipulation.

2. Anonymous mapping: It is a memory-mapped region where there is no connection with any file/device. Or we can say it is used for dynamic allocation of memory within a program.

  • Private Anonymous Mapping: This is an area of memory that does not have a file associated with it. It is commonly used for dynamic allocation. Custom memory allocators are examples of this type of mapping.
  • Shared Anonymous mapping: Inter-process communication is a type of shared mapping in which multiple processes can have access to and change the data. An example of this is implementing Inter-process communication (IPC).

3. Device Mapping: In this type, Registers, hardware devices like graphic cards, and network adapters can be mapped into the process’s address space.

Memory Mapping

Modern computers have a virtual memory that is not physically present. We can achieve it by setting up a Hard disk, this way extended memory is called virtual memory. So any program that is inside the computer will have a virtual memory address to store data. This data cannot be used unless it is converted to a physical address. So, In short, Memory Mapping is the process done by the Operating System to translate Virtual memory addresses to physical addresses. So, the program can run anytime when the OS loads it as it is required.

Similar Reads

What is Memory Mapping?

Memory mapping or mmap() is a function call in an Operating system like Unix. It is a low-level language, and it helps to directly map a file to the currently executing process’s own memory address space. Which could optimize File I/O operations, inter-process communication, etc....

Implementation of Memory-Mapping Algorithm

Memory mapping involves a series of steps. An algorithmic explanation of how memory mapping can be implemented in C is provided here:...

FAQs on Memory Mapping in OS

...

Contact Us