-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNextFitMemorySimulator.java
More file actions
40 lines (35 loc) · 899 Bytes
/
NextFitMemorySimulator.java
File metadata and controls
40 lines (35 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Memory strategy that puts a process in memory at the next fitting location
* in memory.
*/
public class NextFitMemorySimulator extends MemorySimulatorBase {
/**
* Default constructor that initializes the sim using an input file
* @param fileName The input file
*/
public NextFitMemorySimulator(String fileName) {
super(fileName);
}
/**
* Return the index of the first position of the next available slot
* in memory
* @param slotSize The size of the requested slot
* @return The index of the first position of an available requested block
*/
@Override
protected int getNextSlot(int slotSize) {
int spaceAvailable = 0;
for (int i = main_memory.length-1; i >=0; i--) {
if (main_memory[i] == FREE_MEMORY) {
spaceAvailable++;
} else {
if (spaceAvailable < slotSize) {
return -1;
} else {
return i+1;
}
}
}
return -1;
}
}