Skip to content

Refactor Code (MemoryManagementAlgorithms): Pull Up Variable #4145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ public abstract ArrayList<Integer> fitProcess(
int[] sizeOfBlocks,
int[] sizeOfProcesses
);

/**
* A constant value used to indicate that an allocation has not been made.
* This value is used as a sentinel value to represent that no allocation has been made
* when allocating space in an array or other data structure.
* The value is -255 and is marked as protected and final to ensure that it cannot be modified
* from outside the class and that its value remains consistent throughout the program execution.
*
* @author: Ishan Makadia (github.com/intrepid-ishan)
* @version: April 06, 2023
*/
protected static final int NO_ALLOCATION = -255;
}

/**
* @author Dekas Dimitrios
*/
class BestFitCPU extends MemoryManagementAlgorithms {

private static final int NO_ALLOCATION = -255; // if a process has been allocated in position -255,

// it means that it has not been actually allocated.

/**
* Method to find the maximum valued element of an array filled with
Expand Down Expand Up @@ -115,10 +124,6 @@ public ArrayList<Integer> fitProcess(
*/
class WorstFitCPU extends MemoryManagementAlgorithms {

private static final int NO_ALLOCATION = -255; // if a process has been allocated in position -255,

// it means that it has not been actually allocated.

/**
* Method to find the index of the memory block that is going to fit the
* given process based on the worst fit algorithm.
Expand Down Expand Up @@ -179,9 +184,6 @@ public ArrayList<Integer> fitProcess(
*/
class FirstFitCPU extends MemoryManagementAlgorithms {

private static final int NO_ALLOCATION = -255; // if a process has been allocated in position -255,

// it means that it has not been actually allocated.

/**
* Method to find the index of the memory block that is going to fit the
Expand Down Expand Up @@ -237,8 +239,6 @@ public ArrayList<Integer> fitProcess(
*/
class NextFit extends MemoryManagementAlgorithms {

private static final int NO_ALLOCATION = -255; // if a process has been allocated in position -255,
// it means that it has not been actually allocated.
private int counter = 0; // variable that keeps the position of the last registration into the memory

/**
Expand Down