The Wayback Machine - https://web.archive.org/web/20240930164212/https://www.geeksforgeeks.org/difference-between-contiguous-and-noncontiguous-memory-allocation/
Open In App

Difference Between Contiguous and Non-Contiguous Memory Allocation

Last Updated : 03 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Memory management is one of the fundamentals of operating systems that has implications for its performances and use of resources. These are discussed below: Contiguous and non-contiguous allocation of memory Allocation of memory may take either of the following forms: This article enables you to know the difference between the two, how memory is allocated in the two cases, and the most appropriate situations for using each of the methods. 

What is Contiguous Memory Allocation? 

Contiguous memory allocation is basically a method in which a single contiguous section/part of memory is allocated to a process or file needing it. Because of this, all the available memory space resides in the same place together, which means that the freely/unused available memory partitions are not distributed in a random fashion here and there across the whole memory space.

Contiguos Memory Allocation 

The main memory is a combination of two main portions- one for the operating system and other for the user program. We can implement/achieve contiguous memory allocation by dividing the memory partitions into fixed size partitions. 

Advantages of Contiguous Memory Allocation

  • Faster Execution: Less time is consumed in the execution of processes due to the fact that memory is provided in a sequential manner. 
  • Minimal Overhead: There are fewer address translations, which all contribute to the efficiency of the system. 
  • Easier to Control: Organization of the memory in the operating system is sequential, which makes it possible to have efficient control of the processes. 

Disadvantages of Contiguous Memory Allocation

  • Internal and External Fragmentation: It was noted that one way that memory blocks can be implemented is that they may become fragmented, which results in inefficiency. 
  • Limited Multiprogramming: The disadvantage of fixed partitioning is that it hinders the ability to control and allocate several processes. 
  • Wastage of Memory: With fixed partitions, memory can be wasted, especially where its usage is not optimal as required. 

What is Non-Contiguous Memory Allocation?

Non-Contiguous memory allocation is basically a method on the contrary to contiguous allocation method, allocates the memory space present in different locations to the process as per it’s requirements. As all the available memory space is in a distributed pattern so the freely available memory space is also scattered here and there. This technique of memory allocation helps to reduce the wastage of memory, which eventually gives rise to Internal and external fragmentation. 

Non-Contiguos Memory Allocation

Advantages of Non-Contiguous Memory Allocation

  • No Memory Wastage: Dynamic allocation makes sure that memory is used as is available and that there is no memory wasted. 
  • Increased Multiprogramming: Non-contiguous allocation is advantageous where higher degrees of multiprogramming are feasible. 
  • Reduced fragmentation: Based on its primary uses, it mainly minimizes internal fragmentation. 

Disadvantages of Non-Contiguous Memory Allocation

  • Slower Execution: Tasks could be longer in duration because memory is frequently split into blocks. 

Difference Between Contiguous and Non-contiguous Memory Allocation

Contiguous Memory Allocation Non-Contiguous Memory Allocation
Contiguous memory allocation allocates consecutive blocks of memory to a file/process. Non-Contiguous memory allocation allocates separate blocks of memory to a file/process.
Faster in Execution. Slower in Execution.
It is easier for the OS to control. It is difficult for the OS to control.
Overhead is minimum as not much address translations are there while executing a process. More Overheads are there as there are more address translations.
Both Internal fragmentation and external fragmentation occurs in Contiguous memory allocation method. Only External fragmentation occurs in Non-Contiguous memory allocation method.
It includes single partition allocation and multi-partition allocation. It includes paging and segmentation.
Wastage of memory is there. No memory wastage is there.
In contiguous memory allocation, swapped-in processes are arranged in the originally allocated space. In non-contiguous memory allocation, swapped-in processes can be arranged in any place in the memory.

It is of two types:

  1. Fixed(or static) partitioning
  2. Dynamic partitioning

It is of five types:

  1. Paging
  2. Multilevel Paging
  3. Inverted Paging
  4. Segmentation
  5. Segmented Paging
It could be visualized and implemented using Arrays. It could be implemented using Linked Lists.
Degree of multiprogramming is fixed as fixed partitions Degree of multiprogramming is not fixed

Conclusion 

With respect to memory management, whether it is contiguous memory allocation or non-contiguous memory, it has its advantages and disadvantages. Despite the extent that contiguous memory allocation is easier to control and it executes faster than linked allocation, it experiences a problem of fragmentation and wastage of memory.

In contrast, non-contiguous memory allocation employs more memory space but is less efficient when, in terms of execution time, they are slower and are quite complex to manage. I have listed down the advantages and disadvantages of each of the two methods to help you understand the circumstances under which you should apply a particular method for your system. 

Difference Between Contiguous and Noncontiguous Memory Allocation – FAQs 

What is internal fragmentation?

Internal fragmentation is the situation where memory blocks are allocated but invested in them but are not fully utilized while some space in the block is unused. 

Why is contiguous memory allocation faster?

Continuous memory allocation is less time-consuming as compared to noncontinuous memory allocation because of little or no translation of addresses and less control to be exerted by the memory management unit. 

Does non-contiguous memory allocation eliminate fragmentation completely?

No, non-contiguous memory allocation decreases the internal fragmentation but could, however, increase the case of external fragmentation. 

Which memory allocation method supports higher multiprogramming?

Non-contiguous memory allocation favors higher levels of multiprogramming as it permits dynamic allocation of memory blocks.



Similar Reads

Buddy Memory Allocation Program | Set 1 (Allocation)
Prerequisite - Buddy System Question: Write a program to implement the buddy system of memory allocation in Operating Systems.Explanation - The buddy system is implemented as follows- A list of free nodes, of all the different possible powers of 2, is maintained at all times (So if total memory size is 1 MB, we'd have 20 free lists to track-one for
13 min read
Difference between Static allocation and Stack allocation
Static Allocation: Static allocation is a procedure which is used for allocation of all the data objects at compile time. Static allocation is possible only when the compiler knows the size of data object at compile time. In this type of allocation, formation of data objects is not possible under any circumstances at run time. In static allocation,
2 min read
Difference Between Static Allocation and Heap Allocation
In programming, there are two approaches to memory management and these are static allocation and heap allocation. In static allocation, memory is determined at the compile time, where the size and position of each data structure for example arrays, variable are constant throughout the program. While this approach may help to give faster access, it
5 min read
Non-Contiguous Allocation in Operating System
Non-contiguous allocation, also known as dynamic or linked allocation, is a memory allocation technique used in operating systems to allocate memory to processes that do not require a contiguous block of memory. In this technique, each process is allocated a series of non-contiguous blocks of memory that can be located anywhere in the physical memo
6 min read
Difference between Volatile Memory and Non-Volatile Memory
Memory is one of the most fundamental components in computing systems. Broadly, computer memory can be divided into two types namely volatile memory and non volatile memory. Even though both are crucial in the total functioning of the electronics, they are not interchangeable, each playing specific roles. Volatile memory deploys power in order to s
6 min read
Difference between Uniform Memory Access (UMA) and Non-uniform Memory Access (NUMA)
In computer architecture, and especially in Multiprocessors systems, memory access models play a critical role that determines performance, scalability, and generally, efficiency of the system. The two shared-memory models most frequently used are UMA and NUMA. This paper deals with these shared-memory models, explaining their characteristics, adva
5 min read
Difference between Static and Dynamic Memory Allocation in C
Memory Allocation: Memory allocation is a process by which computer programs and services are assigned with physical or virtual memory space. The memory allocation is done either before or at the time of program execution. There are two types of memory allocations: Compile-time or Static Memory AllocationRun-time or Dynamic Memory AllocationStatic
3 min read
Implementing Non-contiguous Memory Management Techniques
Memory Management Techniques are basic techniques that are used in managing the memory in operating system. Memory Management Techniques are basically classified into two categories: (i) Contiguous (ii) Non-contiguous We have already discussed the implementation of contiguous in the article Implementation of Contiguous Memory Management Techniques.
3 min read
MCQ on Memory allocation and compilation process
1. What will be the output of the following code? C/C++ Code #include <stdio.h> #include <stdlib.h> int main() { union test { int i; float f; char c; }; union test* t; t = (union test*)malloc(sizeof(union test)); t->f = 20.60f; printf("%f", t->f); return 0; } (a) Garbage value (b) 20.60000
3 min read
Memory Allocation Techniques | Mapping Virtual Addresses to Physical Addresses
Prerequisite : Requirements of Memory Management System, Logical and Physical Address Memory Allocation Techniques:To store the data and to manage the processes, we need a large-sized memory and, at the same time, we need to access the data as fast as possible. But if we increase the size of memory, the access time will also increase and, as we kno
5 min read
Buddy System - Memory Allocation Technique
Static partition techniques are limited by having a fixed number of active processes, and space use may not be optimal. The buddy system is a memory allocation and management technique that uses power-of-two increments. Assume the memory size is 2U and a size of S is required. In this article, we are going to discuss the Buddy System in detail alon
8 min read
Partition Allocation Methods in Memory Management
In the operating system, the following are four common memory management techniques. Single contiguous allocation: Simplest allocation method used by MS-DOS. All memory (except some reserved for OS) is available to a process. Partitioned allocation: Memory is divided into different blocks or partitions. Each process is allocated according to the re
4 min read
Buddy Memory Allocation Program | Set 2 (Deallocation)
Prerequisite - Buddy Allocation | Set 1 Question: Write a program to implement the buddy system of memory allocation and deallocation in Operating Systems.Explanation - As we already know from Set 1, the allocation is done via the usage of free lists. Now, for deallocation, we will maintain an extra data structure-a Map (unordered_set in C++, HashM
15+ min read
Stack vs Heap Memory Allocation
Memory in a C/C++/Java program can either be allocated on a stack or a heap.Prerequisite: Memory layout of C program. Stack Allocation: The allocation happens on contiguous blocks of memory. We call it a stack memory allocation because the allocation happens in the function call stack. The size of memory to be allocated is known to the compiler and
7 min read
Difference between Random Access Memory (RAM) and Content Addressable Memory (CAM)
Random Access Memory (RAM) is used to read and write. It is the part of primary memory and used in order to store running applications (programs) and program's data for performing operation. It is mainly of two types: Dynamic RAM (or DRAM) and Static RAM (or SRAM). RAM is made up of small memory cells that are arranged in a grid pattern. Each cell
4 min read
Difference between Virtual memory and Cache memory
Cache Memory: Cache memory increases the accessing speed of CPU. It is not a technique but a memory unit i.e a storage device. In cache memory, recently used data is copied. Whenever the program is ready to be executed, it is fetched from main memory and then copied to the cache memory. But, if its copy is already present in the cache memory then t
2 min read
Difference Between Eidetic Memory and Photographic Memory
Difference Between Eidetic Memory and Photographic Memory: Eidetic memory and photographic memory are two distinct forms of human memory. Memory is the capacity to gather, retain, and recall information. This cognitive function hinges on three primary processes: encoding, storage, and retrieval. Human memory encompasses the capacity to maintain and
10 min read
Implementation of Contiguous Memory Management Techniques
Memory Management Techniques are basic techniques that are used in managing the memory in the operating system. In this article, we will deal with the implementation of Continuous Memory Management Techniques. Memory Management Techniques are classified broadly into two categories: ContiguousNon-contiguous What is Contiguous Memory Management?Conti
4 min read
Random Access Memory (RAM) and Read Only Memory (ROM)
Memory is a fundamental component of computing systems, essential for performing various tasks efficiently. It plays a crucial role in how computers operate, influencing speed, performance, and data management. In the realm of computer memory, two primary types stand out: Random Access Memory (RAM) and Read-Only Memory (ROM). Understanding the diff
9 min read
Allocation of frames in Operating System
An important aspect of operating systems, virtual memory is implemented using demand paging. Demand paging necessitates the development of a page-replacement algorithm and a frame allocation algorithm. Frame allocation algorithms are used if you have multiple processes; it helps decide how many frames to allocate to each process. There are various
3 min read
Resource Allocation Techniques for Processes
The Operating System allocates resources when a program need them. When the program terminates, the resources are de-allocated, and allocated to other programs that need them. Now the question is, what strategy does the operating system use to allocate these resources to user programs? There are two Resource allocation techniques: 1. Resource parti
2 min read
Resource Allocation
To assign the available resources in an economic way is known as resource allocation. The planning of the activities and the resource required by these activities while taking into consideration both resources availability and project time is termed as resource allocation in project management. There are 2 parts of resource allocation: Strategic Pl
2 min read
First-Fit Allocation in Operating Systems
INTRODUCTION: First-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In First-Fit, the operating system searches through the list of free blocks of memory, starting from the beginning of the list, until it finds a block that is large enough to accommodate the memory request from the process.
3 min read
Best-Fit Allocation in Operating System
INTRODUCTION: Best-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In Best-Fit, the operating system searches through the list of free blocks of memory to find the block that is closest in size to the memory request from the process. Once a suitable block is found, the operating system spli
4 min read
Worst-Fit Allocation in Operating Systems
For both fixed and dynamic memory allocation schemes, the operating system must keep a list of each memory location noting which are free and which are busy. Then as new jobs come into the system, the free partitions must be allocated. These partitions may be allocated in 4 ways: 1. First-Fit Memory Allocation 2. Best-Fit Memory Allocation 3. Worst
2 min read
Register Allocation Algorithms in Compiler Design
Register allocation is an important method in the final phase of the compiler . Registers are faster to access than cache memory . Registers are available in small size up to few hundred Kb .Thus it is necessary to use minimum number of registers for variable allocation . There are three popular Register allocation algorithms . Naive Register Alloc
5 min read
Resource Allocation Graph (RAG) in Operating System
As Banker's algorithm using some kind of table like allocation, request, available all that thing to understand what is the state of the system. Similarly, if you want to understand the state of the system instead of using those table, actually tables are very easy to represent and understand it, but then still you could even represent the same inf
5 min read
Channel Allocation Problem in Computer Network
Channel allocation is a process in which a single channel is divided and allotted to multiple users in order to carry user specific tasks. There are user's quantity may vary every time the process takes place. If there are N number of users and channel is divided into N equal-sized sub channels, Each user is assigned one portion. If the number of u
3 min read
Difference between Memory based and Register based Addressing Modes
Prerequisite - Addressing Modes Addressing modes are the operations field specifies the operations which need to be performed. The operation must be executed on some data which is already stored in computer registers or in the memory. The way of choosing operands during program execution is dependent on addressing modes of instruction. "The address
4 min read
Difference between Memory and Hard Disk
Memory and hard disk are two essential components of a computer system. Memory refers to the temporary storage used by a computer to perform its operations, while a hard disk is a permanent storage device used to store data and programs. 1. Memory: Memories are made up of registers. Memory refers to the location of short-term data. Each register in
4 min read