Contiguous Memory Allocation in RAM

2
0

Introduction

Contiguous memory allocation is one of the simplest ways to place a process in physical memory. The idea is direct: if a process needs memory, the operating system gives it one continuous block of RAM.

This model is easy to understand because the whole process stays in one unbroken region. Its simplicity is also its limitation, because RAM can become fragmented as processes enter and leave memory.

What Contiguous Memory Allocation Means

Contiguous memory allocation means that each process is loaded into a single continuous block of physical memory.

If a process needs 8000 memory locations, the OS tries to find one free block of 8000 consecutive locations. It does not split the process across several different holes in RAM.

This makes address translation simple, but it also means allocation can fail if no single free block is large enough.

Why This Method Exists

Contiguous allocation gives a very simple memory-management model. The operating system only needs to remember where the process starts and how large its allocated block is.

The main rules are:

  • One process: The process gets one continuous physical memory block.

  • One free hole: The selected free block must be large enough for the whole process.

  • Consecutive addresses: The process occupies adjacent physical addresses in RAM.

This model is useful for understanding early memory allocation and the reason later techniques, such as paging, were introduced.

Contiguous Memory Allocation and its Need

Contiguous Memory Allocation and its Need

Base and Limit Registers

In contiguous allocation, the OS uses two important values:

  • Base: Starting physical address of the process block

  • Limit: Size of the process block and legal access boundary

If a process has base = 30000 and limit = 8000, then the process can use logical addresses from 0 to 7999.

Address translation works like this:

  • Valid address: If logical_address < limit, calculate physical_address = base + logical_address.

  • Invalid address: If logical_address >= limit, reject the access as an invalid memory access.

The limit is checked first. Only valid logical addresses are translated into physical addresses.

Relocation and Protection

Base and limit provide two important benefits.

Relocation: A process can be placed at different physical locations. If the base changes, the same logical address can map to a different physical address.

Protection: A process cannot legally access memory outside its allocated block. If the logical address is greater than or equal to the limit, the access is invalid.

So the relationship is simple: base tells where the block starts, and limit tells how far the process is allowed to go.

Allocation and Deallocation Flow

When a new process arrives, the OS searches for a free hole large enough to hold the complete process.

A compact allocation flow is:

  • Process arrives: The OS receives a memory request.

  • Free holes are checked: The OS looks for a continuous free block.

  • A suitable block is selected: The chosen block must fit the whole process.

  • Base and limit are assigned: Base stores the starting address, and limit stores the size.

  • Process runs: The process uses logical addresses that are translated into physical addresses.

Deallocation happens when a process exits. Its memory block is marked as free. If neighboring free blocks are adjacent, the OS may merge them into one larger free block, making future allocations easier.

Allocation and Deallocation Flow

Allocation and Deallocation Flow

Small Address Translation Example

Suppose a process has Base as 30000 and Limit as 8000.

For logical address 3500, the check is 3500 < 8000, so the access is valid. The physical address is 30000 + 3500 = 33500.

For logical address 9000, the check is 9000 < 8000, which is false. The access is invalid because the process is trying to go beyond its allocated block.

The important order is: check the limit first, then add the base.

External Fragmentation

The biggest problem with contiguous memory allocation is external fragmentation.

External fragmentation means free memory exists, but it is split into separate holes instead of being available as one large continuous block.

For example, suppose free memory is divided like this:

Hole 1

Hole 2

Hole 3

Hole 4

20 KB

40 KB

30 KB

25 KB

The total free memory is 115 KB. But if a new process needs 100 KB, allocation still fails because no single hole is 100 KB.

This is the main weakness of contiguous allocation: total free memory may be enough, but usable continuous memory may not be enough.

External Fragmentation

External Fragmentation

Why Paging Becomes Useful

Paging solves the main limitation of contiguous allocation by removing the requirement that a process must occupy one continuous physical block.

Instead of placing the entire process in one large hole, paging divides memory into fixed-size pages and frames. A process can then be stored in different physical frames, while the page table keeps track of the mapping.

That is why contiguous allocation is useful as a foundation, but modern memory management usually depends on paging and virtual memory.

Summary

Contiguous memory allocation places each process in one continuous block of physical RAM. It is simple because the OS mainly needs the base address and the limit to translate and protect memory accesses.

Its major limitation is external fragmentation. Free memory may exist in total, but if it is scattered across small holes, a process that needs one large continuous block may still fail to get memory.

CS Core

Read Similar Blogs

Comments0