public List <hole> copy(List <hole> t) { List <hole> w = new List <hole>(); for (int i = 0; i < t.Count; i++) { hole first = new MemoryManagmentVisualization.hole(t[0].start, t[0].size); first.alocated = t[i].alocated; first.hole_id = t[i].hole_id; first.name = t[i].name; first.process_index = t[i].process_index; w.Add(first); } return(w); }
public void fix() { hole.sort(holes); List <hole> tempHoles = new List <hole>(0); hole tempBig = new MemoryManagmentVisualization.hole(0, 0); while (holes.Count > 0) { hole temp = holes[0]; holes.RemoveAt(0); if (temp.alocated) { tempHoles.Add(tempBig); tempBig = new MemoryManagmentVisualization.hole(0, 0); tempHoles.Add(temp); } else { if (tempBig.size == 0) { tempBig = temp; } else if (temp.start == tempBig.start + tempBig.size) { tempBig.size = tempBig.size + temp.size; } else { tempHoles.Add(tempBig); tempBig = temp; } } } if (tempBig.size > 0) { tempHoles.Add(tempBig); } holes = tempHoles; hole.sort(holes); for (int i = 0; i < holes.Count; i++) { if (holes[i].size == 0) { holes.RemoveAt(i); i--; } } }
public void computeWorstFit() { while (processes.Count > 0) { process temp = processes[0]; processes.RemoveAt(0); List <hole> tempHoles = new List <hole>(); tempHoles = copy(holes); int allocated = 0; for (int i = 0; i < temp.no_of_segments; i++) { hole.sort2(tempHoles); tempHoles.Reverse(); for (int j = 0; j < tempHoles.Count; j++) { if (tempHoles[j].alocated == false && tempHoles[j].size >= temp.segmenst_sizes[i]) { hole tempHole = new MemoryManagmentVisualization.hole(tempHoles[j].start, tempHoles[j].size); tempHole.alocated = false; tempHoles.RemoveAt(j); int remainSize = tempHole.size - temp.segmenst_sizes[i]; tempHole.size = temp.segmenst_sizes[i]; allocated++; tempHole.alocated = true; tempHole.name = temp.name_of_segment[i]; tempHole.process_index = temp.process_id; tempHoles.Add(tempHole); if (remainSize > 0) { tempHoles.Add(new hole(tempHole.start + tempHole.size, remainSize)); } break; } } } if (allocated == temp.no_of_segments) { holes = copy(tempHoles); } else { holdProcesses.Add(temp); } } }