Contiguous and Non Contiguous Memory
Contiguous and Non Contiguous Memory
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.
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
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.
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.
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.
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.
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.