From 092970ce693263d995e8e527d8c437f8f24ac9ee Mon Sep 17 00:00:00 2001 From: Ishan Makadia Date: Thu, 6 Apr 2023 03:56:24 -0300 Subject: [PATCH 1/2] refactor: pull up variable --- .../others/MemoryManagementAlgorithms.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java b/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java index 3ab711d27dc6..a35db125147b 100644 --- a/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java +++ b/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java @@ -25,6 +25,18 @@ public abstract ArrayList 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; } /** @@ -32,7 +44,6 @@ public abstract ArrayList fitProcess( */ 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. @@ -115,8 +126,6 @@ public ArrayList 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. /** @@ -179,7 +188,6 @@ public ArrayList 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. @@ -237,7 +245,6 @@ public ArrayList 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 From 29e96b95e0ee858dfe9d6e2e68b0843b4c88e9c6 Mon Sep 17 00:00:00 2001 From: Ishan Makadia Date: Thu, 6 Apr 2023 04:00:07 -0300 Subject: [PATCH 2/2] chore: cleanup stale comments --- .../thealgorithms/others/MemoryManagementAlgorithms.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java b/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java index a35db125147b..576d83a9789f 100644 --- a/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java +++ b/src/main/java/com/thealgorithms/others/MemoryManagementAlgorithms.java @@ -45,8 +45,6 @@ public abstract ArrayList fitProcess( class BestFitCPU extends MemoryManagementAlgorithms { - // it means that it has not been actually allocated. - /** * Method to find the maximum valued element of an array filled with * positive integers. @@ -126,8 +124,6 @@ public ArrayList fitProcess( */ class WorstFitCPU extends MemoryManagementAlgorithms { - // 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. @@ -189,8 +185,6 @@ public ArrayList fitProcess( class FirstFitCPU extends MemoryManagementAlgorithms { - // 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 first fit algorithm. @@ -245,7 +239,6 @@ public ArrayList fitProcess( */ class NextFit extends MemoryManagementAlgorithms { - // 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 /**