Contiguous Allocation
Definition:
Contiguous allocation is a file allocation method in which all the blocks of a file are stored in
continuous/sequential memory locations on the disk.
Characteristics:
1. File occupies adjacent memory blocks.
2. Stores starting address and length of file.
3. Easy to implement and manage.
4. Supports fast access to files.
Advantages:
1. Simple and easy to implement.
2. Supports sequential and direct access.
3. Fast read/write performance.
4. Requires less seek time.
Disadvantages:
1. Causes external fragmentation.
2. Difficult to increase file size after allocation.
3. May waste space if allocated block is larger than needed.
Linked Allocation
Definition:
Linked allocation is a file allocation method in which file blocks are stored anywhere on the
disk, and each block contains a pointer to the next block.
Characteristics:
1. Blocks are not stored continuously.
2. Each block points to the next block in the file.
3. Directory stores starting and ending block of file.
4. Suitable for sequential access.
Advantages:
1. No external fragmentation.
2. File size can grow easily.
3. Efficient use of disk space.
4. Simple allocation of free blocks.
Indexed Allocation
Definition:
Indexed allocation is a file allocation method in which each file has an index block that
stores the addresses of all disk blocks occupied by that file.
Characteristics:
1. Uses a separate index block for each file.
2. Index block contains pointers to all file blocks.
3. Supports direct/random access of files.
4. Eliminates external fragmentation.
5. Any free block on disk can be allocated.
Advantages:
1. Supports sequential and direct access.
2. No external fragmentation.
3. Faster than contiguous and linked allocation.
4. Supports fixed and variable size blocks.
Disadvantages:
1. Wastage of space due to index block.
2. Pointer overhead is higher.
3. Extra memory required for storing index block.
Disadvantages:
1. Does not support efficient direct/random access.
2. Pointer in each block uses extra space.
3. If one pointer is lost, file data may be lost.
4. Slower than contiguous allocation.
File Access Methods
File access method defines how data is read and written in a file.
Types:
1. Sequential Access
2. Direct/Random Access
3. Indexed Sequential Access
1) Sequential Access Method
Data is accessed one by one in order.
Starts from beginning and moves sequentially.
Cannot skip records.
Advantages:
Simple to use
Suitable for processing all records
Disadvantages:
Slow performance
Search takes more time
Example: Compiler, Text Editor
2) Direct Access Method
Data can be accessed directly at any position.
Also called Random Access Method.
Used in hard disks.
Advantages:
Fast access
No need to read all previous records
Disadvantages:
Poor I/O utilization
More CPU time required
Example: Editors
3) Indexed Sequential Access
Combination of sequential and direct access.
Uses index to locate records quickly.
Advantages:
Faster searching
Supports both sequential and direct access
Disadvantages:
Extra storage needed for index
Complex method
Producer–Consumer Problem
The Producer–Consumer Problem is a classic problem in Operating System related to
process synchronization.
Concept:
There are two processes:
o Producer → produces data/items
o Consumer → consumes data/items
Both share a common memory area called a buffer.
Working:
Producer adds items to the buffer.
Consumer removes items from the buffer.
The buffer has limited size.
Problem:
If buffer is full, producer must wait.
If buffer is empty, consumer must wait.
Need proper synchronization to avoid:
o Data inconsistency
o Race condition
Solution:
Use synchronization tools like:
o Semaphore
o Mutex
Ensures:
o No overflow (buffer full)
o No underflow (buffer empty)
Example:
Printer queue system
File downloading and saving
File Access Method
Definition:
File access method defines the way data is read from and written to a file in the computer
system.
Types / Characteristics:
1. Sequential Access Method
Data is accessed one record after another in sequence.
Cannot skip records directly.
2. Direct Access Method
Data can be accessed directly/randomly from any location.
No need to read previous records.
3. Indexed Sequential Access Method
Combines both sequential and direct access using an index.
Uses index table to locate records quickly.
Advantages:
1. Easy data retrieval and storage.
2. Supports efficient file handling.
3. Different methods suit different applications.
4. Improves performance based on access type.
Disadvantages:
1. Sequential access is slower for random searches.
2. Direct access requires more memory management.
3. Indexed method needs extra storage for index.