Contiguous Memory Allocation
Contiguous memory allocation is one of the memory management techniques in an Operating System (OS) in which memory is allocated to processes in contiguous blocks (side by side). In this technique, the entire process is loaded into memory as one single continuous chunk from start to end. Contiguous Memory Management has two types:
- Fixed (or Static) Partition
- Variable (or Dynamic) Partitioning
Fixed Partitioning
In the fixed partition, main memory is divided into a fixed number of partitions at system startup. Fixed means number of partitions are fixed in the memory.
- The number of partitions is fixed and cannot change at runtime.
- Each partition can hold only one process at a time.
- Maximum size of a process is limited by the largest partition size.
- The OS maintains base and limit registers for every partition to ensure a process doesn’t cross its boundary.
Advantages
- Simple to implement
- Easy memory management (just allocate a partition)
- Protection ensured by limit registers
Disadvantages
- Internal Fragmentation (waste inside partitions) is found in fixed partition. Space wasted inside a partition because process < partition size. Example: Process = 180 MB, Partition = 256 MB → 76 MB wasted.
- The degree of multiprogramming is directly proportional to the number of partitions means the maximum number of processes that can run = number of partitions. If there are 4 partitions, only 4 processes can run, even if memory has free space.
- Maximum process size should always be less than equal to maximum partition size. If a process is larger than the biggest partition, it cannot be loaded into memory at all. Example: Max partition = 256 MB, Process = 300 MB → cannot fit.
Variable Partitioning
Variable Partitioning is a contiguous memory allocation technique where memory is divided dynamically to fit the exact size of processes. Unlike fixed partitioning, the partitions are not predefined — they are created at runtime as processes arrive. If the smaller processes keep on coming then the larger partitions will be made into smaller partitions.
- Partition size is equal to the size of the process.
- Number of partitions is not fixed; it changes as processes enter and leave memory.
- More flexible and efficient than fixed partitioning (less internal waste).
- Still suffers from external fragmentation.
Example
Step 1 – Initial Memory = 1000MB (Empty)
Step 2 – Processes arrive
P1 = 200 MB, P2 = 300 MB, P3 = 100 MB
Step 3 – If P2 finishes (hole created)
Step 4 – New Process Arrives (P4 = 450 MB)
- Total free memory = 300 MB + 400 MB = 700 MB
- But memory is not contiguous (split into two holes).
- So, P4 (450 MB) cannot fit, even though free space is enough.
This problem is called External Fragmentation.
Solution of External Fragmentation
The main method used by Operating Systems to deal with external fragmentation is called Compaction. In compaction, the OS shifts processes in memory so that all free blocks get merged into one large continuous block. It removes the scattered “holes” and allows larger processes to fit.
In Above Example
Step 1 – After P2 finishes
Free = 700 MB (but in two parts: 300 + 400). P4 = 450 MB cannot fit here.
Step 2 – After Compaction
The OS shifts P3 just after P1, combining the two free spaces:
Step 3 – Allocate P4
Now we can place P4 (450 MB) inside the free block:
Now the process fits successfully.
Dynamic Storage Allocation Algorithms
When allocating partitions dynamically, OS can use:
First Fit:
First Fit is a memory allocation strategy used in variable partitioning. In this method, the operating system allocates the first free block (hole) that is large enough to satisfy the process request.
- The search begins from the beginning of memory.
- Stops as soon as a suitable hole is found.
When a process arrives:
- Scan memory from the start.
- Select the first hole large enough for the process.
- Allocate memory and leave the rest (if any) as a smaller free block.
Best Fit:
Best Fit is a memory allocation strategy used in variable partitioning. In this method, the operating system searches the entire list of free blocks (holes) and allocates the smallest block that is large enough to satisfy the process request.
- Tries to minimize wasted space (internal unused part).
- Unlike First Fit, it does not stop early — it scans the full list.
When a process arrives:
- Search all free holes.
- Pick the smallest hole that can fit the process.
- Allocate process → remaining part (if any) becomes a smaller free block.
Worst Fit:
In this method, the OS allocates the largest available free block (hole) to a process, even if a smaller one could fit. It is opposite of Best Fit.
When a process arrives:
- Search all free holes.
- Pick the largest hole.
- Allocate process → remaining block becomes smaller free space.
Contiguous Memory Allocation is the simplest memory management technique in Operating Systems where each process is stored in a single continuous block of memory. It can be done using Fixed Partitioning or Variable Partitioning.
It is easy to implement and ensures fast access since processes are stored in a single block. However, it suffers from fragmentation and inflexibility, making it unsuitable for modern multiprogramming systems.
That’s why advanced techniques like Paging and Segmentation are widely used today to overcome these limitations.