Difference between Contiguous and Noncontiguous Memory Allocation in Operating System

The file allocation strategy is adopted by the operating system to improve the space efficiency and reduce the time complexity. There are mainly two memory allocation techniques that the operating system utilizes to store the file, these are contiguous memory allocation and non-contiguous memory allocation. Some of the operating systems either use one of these two such as IBM mainframe uses contiguous technique but many operating systems can use both of them, it depends on the need of the task that the operating system is utilized for.


Contiguous memory allocation

Contiguous memory allocation is a method of file allocation where the file blocks are stored in the memory in a sequential manner. In contiguous memory allocation, the main memory is subdivided into various file blocks and when the data of the files are stored one after other without consideration of size or priority then it is said to be contiguously allocated. Also, there is a directory that exists in this allocation and whenever any new file is stored it is first broken into fixed-sized blocks to he stored in main memory and the starting file block address is stored in the directory so that when the operating system tries to find the same file later on it can easily search it in the directory and jump to the particular starting address. The only problem that the contiguous memory allocation faces is the growth of the file since when the contiguous allocation of the file occurs it allocates a complete memory block to the file to store it sequentially. So later when the file needs to add more information it may cause problems because the memory size is already fixed during the allocation and this problem is solved in the non-contiguous memory allocation.


Non-contiguous memory allocation

In non-contiguous memory allocation, the file is allocated in a random address rather than sequential order. The reason why they are allocated in a random address is that the non-contiguous memory allocation compares the size of the file block and the size of the memory block and then allocated the block depending on the file size in the memory block whichever it finds first. Also whenever the file needs to add more information then it allocates more blocks of memory that are present in the memory and the address of the new block is saved in the previous block. This way the non-contiguous memory helps the file to add more information according to the need. The non-contiguous memory allocation also has a directory similar to the contiguous memory allocation. 


Contiguous and non-contiguous memory allocation

The blocks are allocated sequentially in the memory The blocks are allocated randomly in the memory
The technique is faster in execution because the searching of the file is quick The technique is slower in execution because the searching of the file is slow
There are fewer numbers overheads to store the address of the next file blocks and therefore less number of address translation There is more number of overheads it requires to store the address of file blocks and therefore more number of address translation
The internal and external fragmentation occurs in the contiguous memory allocation The non-contiguous memory allocation completely eliminate the fragmentation that occurs in the main memory
The file growth is limited and difficult to store more information The file growth is not limited and the information storage can occur easily
Fragmentation leads to wastage of memory space There is no wastage of memory and there is non-fragmentation
The size of the file has to be declared during the time of storage of the memory block and is fixed from thereon The size of the file can be increased by adding overheads of the next block address therefore it does have to be declared earlier


Leave a Comment