Contiguous and Non - Contiguous Memory Allocation in Operating System
A large collection of bytes is referred to as memory, and memory allocation is the process of allocating space to computer programmes. Contiguous and non-contiguous memory allocation is the two primary forms.
The tasks can be finished in a single memory region thanks to contiguous memory allocation. Non-contiguous memory allocation, on the other hand, distributes the procedure throughout several memory locations in various memory sections.
Contiguous Memory Allocation:
The mechanism of memory allocation is what it is. A single continuous piece of memory blocks is given when a process requests memory, depending on the needs of the process.
The task is finished by creating fixed-sized memory partitions and designating a single process to each partition. However, it will restrict the amount of multiprogramming to the number of done fixed partitions in memory.
Internal fragmentation is a side effect of this allocation. For instance, let's say the demand for a process's fixed-sized memory block is a little bit more than the block's size. In that situation, internal fragmentation is the term used to describe the remaining memory space in the block.
A partition becomes available for use by another process when a process within it has completed.
In the variable partitioning scheme, the OS keeps track of a table that lists the memory partitions that are free and used by processes. Allocating memory in contiguous blocks reduces address translation overheads, accelerating process execution.
Advantages:
- How many memory blocks are still available influences how much additional memory may be allocated to processes, and this information is easy to keep track of.
- Due to the ability to read the entire file from the disc in a single task, contiguous memory allocation has good read performance.
- It's easy to set up and works well to use the contiguous allotment.
Disadvantages:
- Because every new file may be written to the end of the disk after the previous one, fragmentation is not a problem.
- It must be aware of the final size of the file before creating it in order to choose the proper hole size.
- It would be essential to compress or repurpose the extra space in the holes once the disc is fully utilised.
Non - Contiguous Allocation:
Depending on its needs, it enables a process to obtain several memory blocks in different parts of memory. Because it makes use of the memory gaps left by internal and external fragmentation, non-contiguous memory allocation also decreases memory waste brought on by internal and external fragmentation.
Paging and segmentation are the two techniques for separating a process' physical address space. Blocks (pages or segments) of the process are split up into non-contiguous memory allocations, which are then distributed throughout various memory spaces according to the amount of available memory.
Although non-contiguous memory allocation can save wasted memory, it also adds to the costs associated with address translation. The memory execution is hindered because address translation takes time when the process pieces are stored in different places in memory.
Advantages:
- Although it provides the benefit of lessening memory waste, the address translation results in an increase in overhead.
- Due to the time required for address translation, it slows down memory execution.
Disadvantages:
- The drawback of this memory allocation is that it requires lengthy traversals of other nodes in order to access them because pointers are needed to get there.
Differences between Contiguous Memory Allocation and Non – Contiguous Memory Allocation:
- The process is given a single memory contiguous block as part of the contiguous memory allocation. Contrarily, a non-contiguous allocation divides the task into numerous blocks and stores them in various memory address spaces.
- A table indicating which partitions are available and being used by the process must be kept by the operating system in contiguous memory allocation. The base address of each process block that is placed in memory space is preserved in a table for each process in non-contiguous memory allocation, in contrast.
- Due to the process' storage in contiguous memory space and contiguous memory allocation, there is no execution-related overhead associated with address translation. In contrast, since the process blocks are dispersed throughout the memory space when memory is allocated in a non-contiguous manner, there is an additional burden associated with address translation during the execution of the process.
- Contiguous memory allocation can be better managed by the operating system. The Non-Contiguous Memory Allocation, on the other hand, is challenging for the Operating System to control.
- Contiguous Memory Allocation allows for speedier processing because the entire process is contained within a single sequential block. In contrast, because the process is running in multiple locations throughout the memory, the execution of its non-contiguous memory allocation is slowed down.
- Two memory allocations are included in a contiguous memory allocation: a single partition and a multi-partition. Paging and segmentation, on the other hand, are part of the non-contiguous memory allocation.
- Fragmentation in the contiguous memory allocation happens both internally and externally. The opposite is true when memory is allocated in a non-contiguous manner.
- In the contiguous memory allocation, swapped-in processes are put in the beginning space. Those processes that are swapped in during a non-contiguous memory allocation, however, can be set up anywhere in memory.
- Only one memory contiguous block is allotted to the process via contiguous memory. The process is divided up into a number of blocks that are each given their own memory address space thanks to non-contiguous memory.
- Execution times for contiguous memory are significantly faster than those for non - contiguous memory allocation. Non- contiguous memory allocation and execution are slower than contiguous memory allocation and execution.
- Because the process is maintained in contiguous memory space in a contiguous memory allocation, there is no overhead associated with address translation during execution. Because the process blocks are dispersed throughout the memory space, there is an overhead of address translation when a process is being executed.
- Most of the time, the operating system keeps a database that lists all of the contiguous memory allocation's available and occupied partitions. Each process in the non-contiguous memory allocation is required to maintain a table that principally provides the base addresses that the memory has obtained for each block.