CONTIGUOUS MEMORY ALLOCATION Contiguous Memory Allocation is a memory management technique where each process is allocated a single continuous block of memory. This approach is simple and efficient...
Contiguous Memory Allocation is a memory management technique where each process is allocated a single continuous block of memory. This approach is simple and efficient in terms of access speed because the CPU can easily calculate the address of any location within the block.
However, contiguous memory allocation suffers from fragmentation. External fragmentation occurs when there are sufficient total free memory spaces, but these are not contiguous, making it difficult to allocate large blocks of memory. Internal fragmentation happens when allocated memory blocks are slightly larger than the requested memory, leading to wasted space.
Additionally, the process of fitting processes into memory can be complex, requiring strategies like first-fit, best-fit, or worst-fit to manage available memory effectively.
Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory. In paging, the physical memory is divided into fixed-size blocks called frames, and the logical memory (used by processes) is divided into blocks of the same size called pages. When a process is loaded into memory, its pages can be loaded into any available memory frames, and a page table keeps track of the mapping between the process’s pages and the physical frames.
This allows the physical address space to be non-contiguous, which solves the problem of external fragmentation and makes it easier to allocate memory efficiently. Paging also simplifies memory management by eliminating the need for complex allocation algorithms.
The page table is a data structure used in paging to store the mapping between virtual addresses and physical addresses. Each entry in a page table corresponds to a page of the process's logical address space and contains the address of the frame in physical memory where the page is stored.
Page tables can be implemented in several ways, including single-level, multi-level, and inverted page tables. A single-level page table is a simple array, but it can become very large if the address space is large.
Segmentation is a memory management technique that divides the process's memory into variable-sized segments, each of which can be a logical unit such as a function, array, or data structure. Unlike paging, segments vary in length, reflecting the logical structure of the process.
Each segment has a segment number and a length, and memory addresses within a segment are specified by an offset from the segment's base address.
A segment table keeps track of each segment's base address and length. Segmentation facilitates sharing and protection, as segments can be independently protected and shared between processes, enhancing modularity and security.
Feature | Paging | Segmentation |
---|---|---|
Memory Division | Fixed-sized blocks called pages | Variable-size blocks called segments |
Physical Memory | Divided into frames of the same size as pages | Divided into segments of varying sizes |
Address Structure | Single-level address with page number and offset | Two-level address with segment number and offset |
Fragmentation | Eliminates external fragmentation, may cause internal fragmentation within pages | Can lead to external fragmentation, but no internal fragmentation |
Logical Division | Divides memory without considering logical structure | Divides memory according to logical structure (e.g., functions, arrays) |
Ease of Management | Simpler due to fixed-size pages | More complex due to variable-size segments |
Protection and Sharing | Easier to manage protection and sharing at page level | More intuitive for logical groupings but complex |
Memory Access | Uniform size makes access time consistent | Variable sizes can lead to varying access times |
Use Case | Commonly used in modern operating systems | Less common, used for specific applications requiring logical division |
Special thanks to Gauri Tomar for contributing to this article on takeUforward. If you also wish to share your knowledge with the takeUforward fam, please check out this article.