Home » Contiguous and Non-Contiguous Memory Allocation in Operating System

Contiguous and Non-Contiguous Memory Allocation in Operating System

by Online Tutorials Library

Contiguous and Non-Contiguous Memory Allocation in Operating System

Memory is a huge collection of bytes, and memory allocation refers to allocating space to computer applications. There are mainly two types of memory allocation: contiguous and non-contiguous memory allocation. Contiguous memory allocation allows a single memory space to complete the tasks. On the other hand, non-contiguous memory allocation assigns the method to distinct memory sections at numerous memory locations.

In this article, you will learn about contiguous and non-contiguous memory allocation with their advantages, disadvantages, and differences.

What is Contiguous Memory Allocation?

It is the type of memory allocation method. When a process requests the memory, a single contiguous section of memory blocks is allotted depending on its requirements.

It is completed by partitioning the memory into fixed-sized partitions and assigning every partition to a single process. However, it will limit the degree of multiprogramming to the number of fixed partitions done in memory.

This allocation also leads to internal fragmentation. For example, suppose a fixed-sized memory block assigned to a process is slightly bigger than its demand. In that case, the remaining memory space in the block is referred to as internal fragmentation. When a process in a partition finishes, the partition becomes accessible for another process to run.

The OS preserves a table showing which memory partitions are free and occupied by processes in the variable partitioning scheme. Contiguous memory allocation speeds up process execution by decreasing address translation overheads.

Advantages and Disadvantages of Contiguous Memory Allocation

There are various advantages and disadvantages of contiguous memory allocation. Some of the advantages and disadvantages are as follows:

Advantages

  1. It is simple to keep track of how many memory blocks are left, which determines how many more processes can be granted memory space.
  2. The read performance of contiguous memory allocation is good because the complete file may be read from the disk in a single task.
  3. The contiguous allocation is simple to set up and performs well.

Disadvantages

  1. Fragmentation isn’t a problem because every new file may be written to the end of the disk after the previous one.
  2. When generating a new file, it must know its eventual size to select the appropriate hole size.
  3. When the disk is filled up, it would be necessary to compress or reuse the spare space in the holes.

What is Non-Contiguous Memory Allocation?

It allows a process to obtain multiple memory blocks in various locations in memory based on its requirements. The non-contiguous memory allocation also reduces memory wastage caused by internal and external fragmentation because it uses the memory holes created by internal and external fragmentation.

The two methods for making a process’s physical address space non-contiguous are paging and segmentation. Non-contiguous memory allocation divides the process into blocks (pages or segments) that are allocated to different areas of memory space based on memory availability.

Non-contiguous memory allocation can decrease memory wastage, but it also raises address translation overheads. As the process portions are stored in separate locations in memory, the memory execution is slowed because time is consumed in address translation.

Advantages and Disadvantages of Non-Contiguous Memory Allocation

There are various advantages and disadvantages of non-contiguous memory allocation. Some of the advantages and disadvantages are as follows:

Advantages

  1. It has the advantage of reducing memory waste, but it increases overhead because of the address translation.
  2. It slows down the memory execution because time is consumed in address translation.

Disadvantages

  1. The downside of this memory allocation is that the access is slow because you must reach the other nodes using pointers and traverse them.

Key differences between the Contiguous and Non-Contiguous Memory Allocation

Here, you will learn the various key differences between Contiguous and Non-Contiguous Memory Allocation. Some of the key differences between Contiguous and Non-Contiguous Memory Allocation are as follows:

Contiguous and Non-Contiguous Memory Allocation in Operating System

  1. The contiguous memory allocation assigns only one memory contiguous block to the process. In contrast, non-contiguous allocation breaks the process into many blocks and stores them in distinct memory address regions.
  2. The operating system must preserve a table in contiguous memory allocation that shows which partitions are available and utilized by the process. In contrast, in non-contiguous memory allocation, a table is preserved for each process containing the base address of each process block placed in memory space.
  3. There is no overhead of address translation during execution because the process is stored in contiguous memory space in contiguous memory allocation. In contrast, in non-contiguous memory allocation, there is an overhead of address translation during process execution since the process blocks are spread across the memory space.
  4. The Operating System can better control contiguous memory allocation. On the other hand, the Non-Contiguous Memory Allocation is difficult for the Operating System to manage.
  5. In Contiguous Memory Allocation, the process runs faster as the entire process is in a sequential block. In contrast, the non-contiguous memory allocation execution of the process is slowed down because the process is in multiple positions in the memory.
  6. Contiguous memory allocation contains two memory allocations: single partition and multi-partition. On the other hand, the Non-Contiguous memory allocation contains Paging and Segmentation.
  7. Both internal and external fragmentation occurs in the contiguous memory allocation. In contrast, non-contiguous memory allocation causes external fragmentation.
  8. Swapped-in processes are placed in the initially allotted space in the contiguous memory allocation. In contrast, swapped-in processes in non-contiguous memory allocation can be organized in any location in memory.

Head-to-head Comparison between the Contiguous and Non-Contiguous Memory Allocation

Here, you will learn the head-to-head comparison between the Contiguous and Non-Contiguous Memory Allocation. Some of the head-to-head comparisons between Contiguous and Non-Contiguous Memory Allocation are as follows:

Contiguous Memory Allocation Non-Contiguous Memory Allocation
It allocates only a single memory contiguous block to the process. It separates the process into numerous blocks, each of which is assigned to a different memory address space.
It is very faster in execution in comparison to non-contiguous memory allocation. It is slower in execution in comparison to contiguous memory allocation.
There is no overhead of address translation during execution because the process is stored in contiguous memory space in contiguous memory allocation. There is an overhead of address translation during process execution because the process blocks are scattered across the memory space.
In most cases, the operating system keeps a table that lists all available and occupied partitions in the contiguous memory allocation. In the non-contiguous memory allocation, each process must keep a table that primarily contains each block’s base addresses acquired by the memory.
The Operating System can better control contiguous memory allocation The Non-Contiguous Memory Allocation is difficult for the Operating System to manage.
Contiguous memory allocation contains two memory allocations: single partition and multi-partition. It contains Paging and Segmentation.
The memory space is partitioned into fixed-sized partitions in the contiguous memory allocation, and each partition is only assigned to one process. It is broken into several blocks, which are then placed in different areas of the memory based on available memory space.
Wastage of memory No wastage of memory
Swapped-in processes are placed in the initially allotted space in the contiguous memory allocation. Swapped-in processes in non-contiguous memory allocation can be organized in any location in memory.
Both internal and exterior fragmentation occurs. The non-Contiguous memory allocation method causes external fragmentation.

Conclusion

Contiguous memory allocation has minimal overheads and speeds up process execution, increasing memory wastage. On the other hand, non-contiguous memory allocation generates address translation overheads, slows process performance, and enhances memory consumption. As a result, both allocation systems have advantages and disadvantages.


You may also like