Contiguous and Non-Contiguous Memory - operating system tutorial


Today we will be discussing Contiguous and Non-Contiguous Memory Allocation - operating system tutorial techniques used in memory management. So, let's start, shall we?

Contiguous Memory


Contiguous Memory

In this when a process is moved from secondary memory to main memory then it is not divided into pieces and as a whole it is placed in main memory.
Arrays is a very good example of contiguous memory allocation because in arrays we allocate contiguous memory.
Advantage of contiguous memory is that access time is very less. You just need to remember the base address. Like in an array you can easily access an element if you know the address of first element in the array because it is in contiguous fashion.
A major disadvantage of contiguous memory allocation is External Fragmentation.



External Fragmentation


Contiguous and Non-Contiguous Memory Allocation

Example: If you have 5KB of data and you want to place it in the above memory block then you cannot place it. Even if you have 8KB free space but that 8KB space is not continuous. That's why you cannot place 5 KB data in the memory.
This is a very common problem in case of Continuous memory allocation.
So external fragmentation means the size of data that we want to insert in the memory is available but we cannot place it because the space is not contiguous.



Non-Contiguous Memory


Non-Contiguous Memory Allocation


In this when a process is moved from secondary memory to main memory then it can be divided into pieces and placed in main memory.
For example linked list. If I ask you can you access the last node of a linked list directly ?
No, because we have only access to first node and with the help of first node we will have to traverse till the last node.
Similarly, in non-contiguous memory allocation, the data is scattered into pieces in the memory and we have access to the starting of that data only.
Advantage of non-contiguous memory allocation is that it will not suffer from external fragmentation.
Example: In case of Non-contiguous memory allocation the 5KB data which we wanted to insert in the picture above can be inserted because 5KB can be broken into pieces (4KB in the first part and remaining 1 KB in the second part).
The disadvantage of non-contiguous memory allocation is that access is very slow because you have to access the other nodes with the help of pointers and one by one you will have to traverse.





Guys you can follow me here if you are interested :


Post a Comment (0)
Previous Post Next Post