Bird
Raised Fist0
Operating Systemsknowledge~6 mins

Contiguous allocation in Operating Systems - Full Explanation

Choose your learning style10 modes available
Introduction
Imagine trying to store a large file on a disk, but the disk space is scattered in small pieces. Contiguous allocation solves this by placing the entire file in one continuous block of storage, making it easier and faster to access.
Explanation
Basic idea
Contiguous allocation means storing a file in one single continuous area on the disk. This way, the file's data blocks are all next to each other, which simplifies finding and reading the file.
Files are stored in one continuous block of disk space.
Advantages
Because the file is stored continuously, the system can quickly calculate where each part of the file is. This leads to faster reading and writing since the disk head moves less.
Contiguous storage allows fast and simple access to files.
Disadvantages
Over time, as files are created and deleted, free space breaks into small pieces. This fragmentation makes it hard to find a large enough continuous space for new files, causing wasted space or delays.
Fragmentation can cause inefficient use of disk space.
Managing fragmentation
To fix fragmentation, systems may rearrange files to create larger continuous free spaces, a process called defragmentation. However, this takes time and resources.
Defragmentation helps restore large continuous free spaces but requires extra effort.
Real World Analogy

Think of a bookshelf where you want to place a long book that takes up several shelves in a row. If the shelves are all together, you can place the book easily. But if the shelves are scattered, you can't fit the book without breaking it.

Basic idea → Placing a long book on consecutive shelves without gaps.
Advantages → Easily finding and reading the book because it is all in one place.
Disadvantages → When shelves are broken up by other books, it’s hard to find enough space for the long book.
Managing fragmentation → Rearranging books to clear enough consecutive shelves for the long book.
Diagram
Diagram
┌─────────────────────────────┐
│ Disk Space                  │
├─────────────┬───────────────┤
│ File A      │ Free Space    │
│ [Contiguous │               │
│ Blocks]    │               │
├─────────────┴───────────────┤
│ Fragmented Free Spaces       │
│ [Small scattered blocks]     │
└─────────────────────────────┘
Diagram showing a file stored in one continuous block and free space fragmented into small pieces.
Key Facts
Contiguous allocation → Storing a file in one continuous block of disk space.
Fragmentation → Breaking of free disk space into small scattered pieces.
Defragmentation → Process of rearranging files to create larger continuous free spaces.
Disk head movement → The physical movement of the read/write arm on a disk drive.
Common Confusions
Believing contiguous allocation means files can be split anywhere on disk.
Believing contiguous allocation means files can be split anywhere on disk. Contiguous allocation requires all parts of a file to be stored together without gaps.
Thinking fragmentation only affects file storage speed.
Thinking fragmentation only affects file storage speed. Fragmentation also causes inefficient use of disk space and can prevent storing large files.
Summary
Contiguous allocation stores files in one continuous block, making access fast and simple.
Fragmentation happens when free space breaks into small pieces, causing storage problems.
Defragmentation rearranges files to restore large continuous free spaces but needs extra time.

Practice

(1/5)
1. What is the main characteristic of contiguous allocation in operating systems?
easy
A. Files are stored in one continuous block of memory.
B. Files are stored in multiple scattered blocks.
C. Files are stored using linked lists.
D. Files are stored in indexed blocks.

Solution

  1. Step 1: Understand file storage methods

    Contiguous allocation means storing a file in one continuous block of memory without breaks.
  2. Step 2: Compare with other methods

    Other methods like linked or indexed allocation store files in scattered blocks or use pointers.
  3. Final Answer:

    Files are stored in one continuous block of memory. -> Option A
  4. Quick Check:

    Contiguous allocation = continuous block storage [OK]
Hint: Contiguous means continuous block storage [OK]
Common Mistakes:
  • Confusing contiguous with linked allocation
  • Thinking files are scattered in contiguous allocation
  • Mixing indexed allocation with contiguous
2. Which of the following is the correct way to describe contiguous allocation?
easy
A. Files are divided into fixed-size blocks scattered across memory.
B. Files use pointers to link scattered blocks.
C. Files occupy a single continuous block of memory.
D. Files are stored in a tree-like index structure.

Solution

  1. Step 1: Identify the definition of contiguous allocation

    Contiguous allocation means the entire file is stored in one continuous block of memory.
  2. Step 2: Eliminate incorrect options

    Options A, B, and D describe other allocation methods like linked or indexed allocation.
  3. Final Answer:

    Files occupy a single continuous block of memory. -> Option C
  4. Quick Check:

    Continuous block = contiguous allocation [OK]
Hint: Continuous block means contiguous allocation [OK]
Common Mistakes:
  • Choosing linked or indexed allocation descriptions
  • Confusing fixed-size blocks with contiguous storage
  • Assuming pointers are used in contiguous allocation
3. Consider a file system using contiguous allocation. If a file of size 10 blocks is stored starting at block 50, which blocks does it occupy?
medium
A. Blocks 60 to 69
B. Blocks 40 to 49
C. Blocks 51 to 60
D. Blocks 50 to 59

Solution

  1. Step 1: Understand starting block and file size

    The file starts at block 50 and occupies 10 continuous blocks.
  2. Step 2: Calculate occupied blocks

    Blocks occupied are from 50 up to 50 + 10 - 1 = 59.
  3. Final Answer:

    Blocks 50 to 59 -> Option D
  4. Quick Check:

    Start 50 + size 10 = blocks 50-59 [OK]
Hint: Start block + size - 1 = last block [OK]
Common Mistakes:
  • Off-by-one errors in block range
  • Starting count from 1 instead of 0
  • Choosing blocks after the last block
4. A file stored using contiguous allocation needs to be extended by 5 blocks, but the next 5 blocks after the file are occupied. What is the main problem here?
medium
A. File cannot be extended because contiguous space is not available.
B. File can be extended by linking scattered blocks.
C. File size can be increased without any issue.
D. File can be moved to another location without fragmentation.

Solution

  1. Step 1: Understand contiguous allocation extension

    Files must occupy continuous blocks; extension requires free blocks immediately after the file.
  2. Step 2: Analyze the problem

    Since the next 5 blocks are occupied, the file cannot be extended contiguously.
  3. Final Answer:

    File cannot be extended because contiguous space is not available. -> Option A
  4. Quick Check:

    Extension needs free contiguous blocks [OK]
Hint: Extension needs free continuous blocks [OK]
Common Mistakes:
  • Assuming scattered blocks can be linked in contiguous allocation
  • Ignoring fragmentation issues
  • Thinking file can grow without moving
5. You have a disk with free blocks scattered as follows: 5 blocks free at 0-4, 3 blocks free at 10-12, and 7 blocks free at 20-26. You want to store a file of size 6 blocks using contiguous allocation. Which free space can you use and why?
hard
A. Blocks 10-12, because they are in the middle of the disk.
B. Blocks 20-25, because they have enough continuous free blocks.
C. Blocks 0-4, because they are the first free blocks.
D. No space is available because all free blocks are scattered.

Solution

  1. Step 1: Identify free block sizes

    Free blocks are 5 at 0-4, 3 at 10-12, and 7 at 20-26.
  2. Step 2: Find a continuous free space of at least 6 blocks

    Only blocks 20-26 have 7 continuous free blocks, enough for 6 blocks.
  3. Final Answer:

    Blocks 20-25, because they have enough continuous free blocks. -> Option B
  4. Quick Check:

    Need ≥6 continuous blocks, only 20-26 fits [OK]
Hint: Choose free space with enough continuous blocks [OK]
Common Mistakes:
  • Choosing smaller free blocks that don't fit file size
  • Ignoring the need for continuous blocks
  • Assuming scattered free blocks can be combined
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard