You are on page 1of 5

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Fall, Year: 2023), B.Sc. in CSE (Day)

Lab Report NO # 03
Course Title: Operating System lab
Course Code: CSE-310 Section: 212-D4

Lab Experiment Name: Simulating the MFT and MVT Memory Management
Techniques.

Student Details
Name Id
Khalid Bin Walid 212002075

Lab Date: 29-11-2023


Submission Date: 05-12-2023
Course Teacher’s Name: Farjana Akter Jui

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
1. Objective:

 To gather knowledge of different memory management techniques.


 To implement Multiprogramming with a Fixed number of Tasks (MFT) and Multiprogramming
with a Variable number of Tasks (MVT).

2. Problem Analysis:

MFT Memory Management Technique


MFT (Multiprogramming with a fixed number of Tasks) is one of the old memory management
Techniques in which the memory is partitioned into fixed-size partitions and each job is assigned to a
Partition. The memory assigned to a partition does not change.

MVT Memory Management Technique


MVT (Multiprogramming with a Variable number of Tasks) is the memory management technique in
which each job gets just the amount of memory it needs. That is, the partitioning of memory is
dynamic and changes as jobs enter and leave the system. MVT is a more “efficient” user of resources.
MFT suffers from the problem of internal fragmentation and MVT suffers from external
fragmentation.

3. Analysis

➔ Implement a code to solve the Memory Management technique problem.

#include <stdio.h>

int main() {
int numBlocks, numProcesses;
printf("Enter the number of blocks: ");
scanf("%d", &numBlocks);

int blockSize[numBlocks], blockSizeCopy[numBlocks], blockAllocation[numBlocks];


int totalMemory = 0, totalMemoryUsed= 0;
for (int i = 0; i < numBlocks; i++) {
printf("Enter size of block %d: ", i +1);
scanf("%d", &blockSize[i]);
blockSizeCopy[i] = blockSize[i];
totalMemory += blockSize[i];
blockAllocation[i] = -1;
}
printf("Enter the number of processes: ");
scanf("%d", &numProcesses);

int processSize[numProcesses];
int totalProcessSizes = 0,
totalProcessSizesUsed = 0;
for (int i = 0; i < numProcesses; i++) {
printf("Enter memory required for process %d: ", i + 1);
scanf("%d", &processSize[i]);
totalProcessSizes += processSize[i];
}
for (int i = 0; i < numProcesses; i++) {
for (int j = 0; j < numBlocks; j++) {
if (blockSize[j] >= processSize[i] && blockAllocation[j] == -1) {
blockAllocation[j] = i;
blockSize[j] -= processSize[i];
totalMemoryUsed +=
processSize[i];
break;
}
}
}
printf("\nProcesses\tProcess size\tBlock\tBlock size\tAllocated\tInt. Frag.\n");
for (int i = 0; i < numProcesses; i++) {
int allocatedBlock = -1;
for (int j = 0; j < numBlocks; j++) {
if (blockAllocation[j] == i) {
allocatedBlock = j;
break;
}
}
if (allocatedBlock != -1) {
printf("%d\t\t%d\t\t%d\t\t%d\t\tYES\t\t%d\n", i + 1, processSize[i],
allocatedBlock + 1, blockSizeCopy[allocatedBlock], blockSizeCopy[allocatedBlock]
- processSize[i]);
} else {
printf("%d\t\t%d\t\t-\t\t-\t\tNO\t\t-\n", i + 1, processSize[i]);
}
}
return 0;
}

4. Input/Output:
Input:
Output:

You might also like