0% found this document useful (0 votes)
2 views2 pages

Adnan

Uploaded by

avinashgkp1919
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Adnan

Uploaded by

avinashgkp1919
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXPERIMENT NO.

5
Implementation of Contiguous Memory Allocation Techniques: Worst Fit and Best Fit

Objective:

To implement and understand memory allocation strategies in operating systems using:

 Worst Fit strategy


 Best Fit strategy

Apparatus/Software Required:

 Computer system with a C/C++ compiler or IDE


 Operating System (Windows/Linux)
 Text Editor (e.g., Code::Blocks, Dev C++, Visual Studio Code)

Theory:

Contiguous memory allocation is a memory management technique in which each process is


allocated a single contiguous block of memory. This method is simple and fast but can lead to
fragmentation. The allocation can be handled using several strategies:

i) Worst Fit

 Allocates memory to the process in the largest available block.


 Leaves large holes, which may be more useful for future processes.
 May cause internal fragmentation due to oversized allocations.

ii) Best Fit

 Allocates memory in the smallest block that is large enough to fit the process.
 Reduces internal fragmentation initially.
 May result in external fragmentation due to many small leftover blocks.

Roll no.2301200100021 2CSE(A) Page 13


Algorithm Steps:

Worst Fit:

1. For each process, find the largest available memory block that fits.
2. Allocate the process to that block.
3. Reduce the size of the block accordingly.
4. If no block fits, mark the process as unallocated.

Best Fit:

1. For each process, find the smallest suitable block.


2. Allocate the process to that block.
3. Reduce the size of the block accordingly.
4. If no suitable block is found, mark the process as unallocated.

Sample Input:

 Memory Blocks: 100 KB, 500 KB, 200 KB, 300 KB, 600 KB
 Process Sizes: 212 KB, 417 KB, 112 KB, 426 KB

Expected Output:

Worst Fit Allocation:

 Process 1 (212 KB) → Block 5


 Process 2 (417 KB) → Block 2
 Process 3 (112 KB) → Block 4
 Process 4 (426 KB) → Not Allocated

Best Fit Allocation:

 Process 1 (212 KB) → Block 3


 Process 2 (417 KB) → Block 2
 Process 3 (112 KB) → Block 1
 Process 4 (426 KB) → Block 5

 Result:The memory allocation techniques Worst Fit and Best Fit were implemented
successfully. Their effectiveness was compared using sample input data, and differences
in allocation patterns were observed.

Roll no.2301200100021 2CSE(A) Page 13

You might also like