1. Introduction
When a process is loaded into memory, it requires space for storing:
Program instructions (code)
Data
Heap
Stack
One of the earliest and simplest memory management techniques is Contiguous Memory Allocation, where each process occupies a single continuous block of memory.
In this approach, all memory locations assigned to a process are adjacent to one another.
2. What is Contiguous Memory Allocation?
Contiguous Memory Allocation is a memory management technique in which each process is allocated a single continuous (adjacent) block of main memory.
Key Idea
| Process A | Process B | Process C |
Each process occupies one uninterrupted region of memory.
A process cannot be split across multiple locations.
3. Memory Layout
In contiguous allocation, memory is typically divided between the operating system and user processes.
Typical Layout
High Address
+-------------------+
| Process 3 |
+-------------------+
| Process 2 |
+-------------------+
| Process 1 |
+-------------------+
| Operating System |
+-------------------+
Low Address
The operating system usually resides in a protected region of memory, while the remaining memory is allocated to processes.
4. Key Components
To support contiguous allocation, the operating system uses special hardware registers.
4.1 Base Register
The Base Register stores the starting physical address of a process.
Example
Base Register = 1000
This means the process begins at physical memory location 1000.
4.2 Limit Register
The Limit Register stores the size of the process's memory region.
Example
Limit Register = 500
The process can access addresses only within the range:
1000 to 1499
Address Translation
When the CPU generates a logical address:
Physical Address = Base + Logical Address
Example
Base = 1000
Logical Address = 200
Physical Address = 1200
Protection Check
The MMU verifies:
Logical Address < Limit
If true:
Access Allowed
Otherwise:
Trap (Memory Protection Fault)
Key Insight
Base and Limit Registers provide:
Relocation
Protection
Simple address translation
5. Types of Contiguous Memory Allocation
Contiguous allocation can be implemented in two major ways:
Fixed Partition Allocation
Variable Partition Allocation
5.1 Fixed Partition Allocation
Concept
Memory is divided into a fixed number of partitions before execution begins.
Each partition can hold exactly one process.
Example
+-----------+
| P1 |
+-----------+
| P2 |
+-----------+
| Empty |
+-----------+
| P3 |
+-----------+
Characteristics
Partitions created in advance
One process per partition
Partition size remains fixed
Advantages
Simple Implementation
Easy to allocate and deallocate memory.
Fast Allocation
Very little management overhead.
Easy Protection
Each partition has predefined boundaries.
Disadvantages
Internal Fragmentation
Unused memory may remain inside allocated partitions.
Limited Multiprogramming
Number of processes is limited by the number of partitions.
Poor Flexibility
Large processes may not fit even when enough total memory exists.
Example of Internal Fragmentation
Suppose:
Partition Size = 100 KB
Process Size = 70 KB
Unused memory:
100 - 70 = 30 KB
This unused space is wasted.
5.2 Variable Partition Allocation
Concept
Memory partitions are created dynamically according to process requirements.
Each process receives exactly the amount of memory it needs.
Example
+-----------+
| P1 200 KB |
+-----------+
| P2 300 KB |
+-----------+
| Free 500KB|
+-----------+
Characteristics
Dynamic partition creation
Variable partition sizes
Better memory utilization
Advantages
Flexible Allocation
Processes receive memory according to their size.
Reduced Internal Fragmentation
Very little wasted space inside allocated blocks.
Better Utilization
Memory is used more efficiently.
Disadvantages
External Fragmentation
Free memory becomes scattered over time.
Complex Management
Allocation and deallocation become more difficult.
6. Allocation Strategies
In variable partition allocation, the operating system must decide where a process should be placed.
Several strategies are used.
6.1 First Fit
Concept
Allocate the first free block large enough to satisfy the request.
Example
Free Blocks:
100 KB
500 KB
200 KB
Request:
150 KB
Allocation:
500 KB block selected
Advantages
Fast
Simple
Disadvantages
Leaves small holes over time
6.2 Best Fit
Concept
Allocate the smallest free block that can accommodate the process.
Example
Free Blocks:
100 KB
500 KB
200 KB
Request:
150 KB
Allocation:
200 KB block selected
Advantages
Minimizes immediate waste
Disadvantages
Slow search
Creates many tiny unusable holes
6.3 Worst Fit
Concept
Allocate the largest available block.
Example
Free Blocks:
100 KB
500 KB
200 KB
Request:
150 KB
Allocation:
500 KB block selected
Advantages
Leaves relatively large free blocks
Disadvantages
May waste large memory regions
7. Comparison of Allocation Strategies
| Strategy | Speed | Memory Utilization | Fragmentation |
|---|---|---|---|
| First Fit | Fast | Good | Moderate |
| Best Fit | Slow | Good initially | High |
| Worst Fit | Moderate | Lower | Moderate |
Exam Insight
Most operating systems historically preferred First Fit because it offers a good balance between speed and utilization.
8. Fragmentation Problem
One of the biggest drawbacks of contiguous allocation is fragmentation.
8.1 Internal Fragmentation
Definition
Unused memory inside an allocated block.
Example
Partition = 100 KB
Process = 75 KB
Unused:
25 KB
This space cannot be used by other processes.
Visualization
+------------------+
| Process 75 KB |
| Unused 25 KB |
+------------------+
8.2 External Fragmentation
Definition
Free memory exists but is scattered into small non-contiguous blocks.
Example
Free Blocks:
50 KB
30 KB
20 KB
Total Free Memory:
100 KB
New Process Requires:
80 KB
Allocation fails because no single block is large enough.
Visualization
+----50----+
| Free |
+----------+
| Process |
+----30----+
| Free |
+----------+
| Process |
+----20----+
| Free |
+----------+
Although enough memory exists overall, it cannot be used.
9. Compaction
Definition
Compaction is the process of moving processes in memory so that all free space is combined into one large contiguous block.
Before Compaction
P1 | Free | P2 | Free | P3 | Free
After Compaction
P1 | P2 | P3 | Free Free Free
Combined Free Space:
One Large Block
Advantages
Eliminates external fragmentation
Improves allocation success rate
Disadvantages
High overhead
Requires relocation support
Time-consuming
10. Advantages of Contiguous Allocation
Simple Design
Easy to understand and implement.
Fast Address Translation
Simple Base + Limit computation.
Low Hardware Requirements
Requires only base and limit registers.
Easy Protection
Memory boundaries are clearly defined.
11. Disadvantages of Contiguous Allocation
Internal Fragmentation
Occurs in fixed partitions.
External Fragmentation
Occurs in variable partitions.
Poor Scalability
Difficult to manage large numbers of processes.
Compaction Overhead
Memory reorganization can be expensive.
Inflexibility
Processes must occupy one continuous region.
12. Contiguous Allocation vs Non-Contiguous Allocation
| Feature | Contiguous Allocation | Non-Contiguous Allocation |
|---|---|---|
| Process Storage | Single Block | Multiple Blocks |
| Flexibility | Low | High |
| Fragmentation | High | Lower |
| Complexity | Low | High |
| Modern Usage | Rare | Common |
Examples of Non-Contiguous Allocation
Paging
Segmentation
Virtual Memory
Modern operating systems primarily use these techniques instead of pure contiguous allocation.
13. Real-World Analogy
Imagine a parking lot.
Contiguous Allocation
A bus requires several adjacent parking spaces.
| Empty | Empty | Empty |
If adjacent spaces are available:
Bus Parks Successfully
If empty spaces are scattered:
| Empty | Car | Empty | Car | Empty |
The bus cannot park even though enough total space exists.
This is exactly the problem of external fragmentation.
14. Exam-Oriented Summary
Contiguous Memory Allocation
Each process occupies one continuous block of memory.
Uses Base and Limit Registers for relocation and protection.
Types
Fixed Partition Allocation
Variable Partition Allocation
Allocation Strategies
First Fit
Best Fit
Worst Fit
Fragmentation
Internal Fragmentation → wasted space inside allocated block
External Fragmentation → scattered free memory
Solution to External Fragmentation
Compaction
Most Important Point
Contiguous memory allocation is simple and efficient for small systems, but fragmentation problems make it unsuitable for modern operating systems, which prefer paging and segmentation.