Contigious and Non Contigious memory allocation in operating system


Introduction

In operating systems, memory allocation refers to the process of assigning memory to different processes or programs running on a computer system. There are two types of memory allocation techniques that operating systems use: contiguous and non-contiguous memory allocation. In contiguous memory allocation, memory is assigned to a process in a contiguous block. In non-contiguous memory allocation, memory is assigned to a process in non-adjacent blocks.

Contiguous Memory Allocation

Contiguous memory allocation is a technique where the operating system allocates a contiguous block of memory to a process. This memory is allocated in a single, continuous chunk, making it easy for the operating system to manage and for the process to access the memory. Contiguous memory allocation is suitable for systems with limited memory sizes and where fast access to memory is important.

Contiguous memory allocation can be done in two ways

  • Fixed Partitioning − In fixed partitioning, the memory is divided into fixed-size partitions, and each partition is assigned to a process. This technique is easy to implement but can result in wasted memory if a process does not fit perfectly into a partition.

  • Dynamic Partitioning − In dynamic partitioning, the memory is divided into variablesize partitions, and each partition is assigned to a process. This technique is more efficient as it allows the allocation of only the required memory to the process, but it requires more overhead to keep track of the available memory.

Advantages of Contiguous Memory Allocation

  • Simplicity − Contiguous memory allocation is a relatively simple and straightforward technique for memory management. It requires less overhead and is easy to implement.

  • Efficiency − Contiguous memory allocation is an efficient technique for memory management. Once a process is allocated contiguous memory, it can access the entire memory block without any interruption.

  • Low fragmentation − Since the memory is allocated in contiguous blocks, there is a lower risk of memory fragmentation. This can result in better memory utilization, as there is less memory wastage.

Disadvantages of Contiguous Memory Allocation

  • Limited flexibility − Contiguous memory allocation is not very flexible as it requires memory to be allocated in a contiguous block. This can limit the amount of memory that can be allocated to a process.

  • Memory wastage − If a process requires a memory size that is smaller than the contiguous block allocated to it, there may be unused memory, resulting in memory wastage.

  • Difficulty in managing larger memory sizes − As the size of memory increases, managing contiguous memory allocation becomes more difficult. This is because finding a contiguous block of memory that is large enough to allocate to a process becomes challenging.

  • External Fragmentation − Over time, external fragmentation may occur as a result of memory allocation and deallocation, which may result in non − contiguous blocks of free memory scattered throughout the system.

Overall, contiguous memory allocation is a useful technique for memory management in certain circumstances, but it may not be the best solution in all situations, particularly when working with larger amounts of memory or if flexibility is a priority.

Non-contiguous Memory Allocation

Non-contiguous memory allocation, on the other hand, is a technique where the operating system allocates memory to a process in non-contiguous blocks. The blocks of memory allocated to the process need not be contiguous, and the operating system keeps track of the various blocks allocated to the process. Non-contiguous memory allocation is suitable for larger memory sizes and where efficient use of memory is important.

Non-contiguous memory allocation can be done in two ways

  • Paging − In paging, the memory is divided into fixed-size pages, and each page is assigned to a process. This technique is more efficient as it allows the allocation of only the required memory to the process.

  • Segmentation − In segmentation, the memory is divided into variable-sized segments, and each segment is assigned to a process. This technique is more flexible than paging but requires more overhead to keep track of the allocated segments.

Non-contiguous memory allocation is a memory management technique that divides memory into non-contiguous blocks, allowing processes to be allocated memory that is not necessarily contiguous. Here are some of the advantages and disadvantages of noncontiguous memory allocation −

Advantages of Non-Contiguous Memory Allocation

  • Reduced External Fragmentation − One of the main advantages of non-contiguous memory allocation is that it can reduce external fragmentation, as memory can be allocated in small, non-contiguous blocks.

  • Increased Memory Utilization − Non-contiguous memory allocation allows for more efficient use of memory, as small gaps in memory can be filled with processes that need less memory.

  • Flexibility − This technique allows for more flexibility in allocating and deallocating memory, as processes can be allocated memory that is not necessarily contiguous.

  • Memory Sharing − Non-contiguous memory allocation makes it easier to share memory between multiple processes, as memory can be allocated in non-contiguous blocks that can be shared between multiple processes.

Disadvantages of Non-Contiguous Memory Allocation

  • Internal Fragmentation − One of the main disadvantages of non-contiguous memory allocation is that it can lead to internal fragmentation, as memory can be allocated in small, non-contiguous blocks that are not fully utilized.

  • Increased Overhead − This technique requires more overhead than contiguous memory allocation, as the operating system needs to maintain data structures to track memory allocation.

  • Slower Access − Access to memory can be slower than contiguous memory allocation, as memory can be allocated in non-contiguous blocks that may require additional steps to access.

In summary, non-contiguous memory allocation has advantages such as reduced external fragmentation, increased memory utilization, flexibility, and memory sharing. However, it also has disadvantages such as internal fragmentation, increased overhead, and slower access to memory. Operating systems must carefully consider the tradeoffs between these advantages and disadvantages when selecting memory management techniques.

Difference between contigious and non contigious memory allocation in operating system

Aspect

Contiguous Memory Allocation

Non-Contiguous Memory Allocation

Method

Allocates memory in a contiguous block to a process

Allocates memory to a process in non-contiguous blocks

Block Size

Memory allocated in a single, continuous chunk

Memory allocated in noncontiguous blocks of varying sizes

Management

Easy to manage by the operating system

Requires additional overhead and can be more complicated to manage

Memory Usage

May result in memory wastage and external fragmentation

Efficient use of memory and reduces fragmentation within memory blocks

Suitable For

Systems with limited amounts of memory and fast access to memory is important

Larger memory sizes and systems that require more efficient use of memory

Advantages

Simple and efficient technique for memory management

More flexible and efficient technique for larger memory sizes and systems that require more efficient use of memory

Disadvantages

Can be inflexible and result in memory wastage and fragmentation

Requires additional overhead and can be more complicated to manage

Conclusion

In conclusion, memory allocation is an important aspect of operating systems, and contiguous and non-contiguous memory allocation are two techniques used to manage memory. Contiguous memory allocation is a simple and efficient technique for allocating memory to processes, but it can result in memory wastage and fragmentation. It is suitable for systems with limited amounts of memory and where fast access to memory is important. Non-contiguous memory allocation, on the other hand, is a more flexible and efficient technique for larger memory sizes and systems that require more efficient use of memory. However, it requires additional overhead and can be more complicated to manage, particularly in the presence of fragmentation within memory blocks. The choice between these two techniques depends on the specific requirements of the system in question, and effective memory management is essential for optimal system performance.

Updated on: 06-Apr-2023

22K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements