Question

In: Computer Science

Write a program using c, c++, or java that have four dynamic memory partitions of size...

Write a program using c, c++, or java that have four dynamic memory partitions of size 100 KB, 500 KB, 200 KB, and 450 KB. The program should accept from user the number of processes and their sizes. Then output the assignment of processes using the next fit algorithm (specifying which process, if any, is block).

Solutions

Expert Solution

source code:

import java.util.Arrays;
public class Main
{
   // Function to allocate memory to blocks as per Next fit
// algorithm
static void NextFit(int blockSize[], int m, int processSize[], int n) {
// Stores block id of the block allocated to a
// process
int allocation[] = new int[n], j = 0;
  
// Initially no block is assigned to any process
Arrays.fill(allocation, -1);
  
// pick each process and find suitable blocks
// according to its size ad assign to it
for (int i = 0; i < n; i++) {
  
// Do not start from beginning
while (j < m) {
  
if (blockSize[j] >= processSize[i]) {
  
// allocate block j to p[i] process
allocation[i] = j;
  
// Reduce available memory in this block.
blockSize[j] -= processSize[i];
  
break;
}
  
// mod m will help in traversing the blocks from
// starting block after we reach the end.
j = (j + 1) % m;
}
}
  
System.out.print("\nProcess No.\tProcess Size\tBlock no.\n");
for (int i = 0; i < n; i++) {
System.out.print( i + 1 + "\t\t" + processSize[i]
+ "\t\t");
if (allocation[i] != -1) {
System.out.print(allocation[i] + 1);
} else {
System.out.print("Not Allocated");
}
System.out.println("");
}
}
  
// Driver program
static public void main(String[] args) {
int blockSize[] = {100, 500, 200,300};
int processSize[] = {100, 250, 300};
int m = blockSize.length;
int n = processSize.length;
NextFit(blockSize, m, processSize, n);
}
}


Related Solutions

using Java, Implement the following algorithm: - Accept 5 different memory partitions and 4 different processes...
using Java, Implement the following algorithm: - Accept 5 different memory partitions and 4 different processes from user and show how best fit algorithm allocates them.
C++ Memory Allocation: 1) Write a C++ program that allocates static, stack, & heap memory. Your...
C++ Memory Allocation: 1) Write a C++ program that allocates static, stack, & heap memory. Your program does not need to do anything else.  Indicate via comments where memory for at least one variable in each memory area is allocated. a) Write code that allocates static memory (only include one declaration): b) Write code that allocates stack memory (only include one declaration): c) Write code that allocates heap memory (only include one declaration): 2) Edit the C++ program below to include...
write a c++ program to read two matrices with any size. Your program should have at...
write a c++ program to read two matrices with any size. Your program should have at least the following functions Main() Read a Matrix Add two matrices Subtract two matrices multiply two matrices display a matrice
Write a code in c++ using dynamic array of structure and dynamic array list. Make a...
Write a code in c++ using dynamic array of structure and dynamic array list. Make a dummy list for a company which stores following information about its customers. Customer ID Customer Name Gender Total items purchased Item category 20% discount in percentage of total purchase amount. Use dynamic array to save at least 20 items by dividing them into 3 different categories. Make a dummy list of items that company sells by dividing them into two categorizes. Items has following...
Write a Java program to 1. read in the size of a square boolean matrix A...
Write a Java program to 1. read in the size of a square boolean matrix A 2. read in the 0-1 matrix elements 3. read in a positive integer n 4. display A^n
Write a Java program to create an array of a specific size (which is an input...
Write a Java program to create an array of a specific size (which is an input from the user) and fill it with random numbers between 1 and 100. Then sort the array and count how many of these numbers are originally at sorted position. Display that original array, the sorted array, and the count (number of elements originally at sorted position).
Write a Java program to 1. read in the size of a square boolean matrix A...
Write a Java program to 1. read in the size of a square boolean matrix A 2. read in the 0-1 matrix elements 3. read in a positive integer n 4. display A^n Multiplying that matrix to the nth power. Like A^2 = matrix A * matrix A. Elements ONLY can be 0 or 1.
Write a program (in C, or Java, or C++, or C#) that creates three new threads...
Write a program (in C, or Java, or C++, or C#) that creates three new threads (besides the already existing main thread) and synchronizes them in such a way that each thread displays it's thread id in turn for 5 iterations. The output of the program should look like this: Thread 1 - iteration no. 1 Thread 2 - iteration no. 1 Thread 3 - iteration no. 1 Thread 1 - iteration no. 2 Thread 2 - iteration no. 2...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester. The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester.    The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT