public int get_parent_process_index() { return(parent_process.get_index()); }
private void add_to_memory(object sender, EventArgs e, Label lbl, process p) { Button b = sender as Button; //sorting descendingly according to size:: try ex p=50,100,200 ;holes sizes=300,100,100;it will not work ////// p.segments_sort_desc();///ES2L FEEHA //renew the holes list and current process in memory Clear the memory panel and then draw it again if (p.get_size() > memory.get_total_empty_space()) { MessageBox.Show("Process" + p.get_index().ToString() + " cannot be added to memory"); return; } //Colning the memory because the defalult assign is by referance in c# ex:memory temp=memory => if we change temp the memory will change due to copying by referrence if (firstfit.Checked == true) { memory temp = memory.copy(); foreach (segment s in p.get_segments()) { int success = 0; foreach (hole h in temp.get_holes()) { if (h.get_size() >= s.get_size()) { hole np = new hole(s.get_size(), h.get_start_location()); np.set_color(s.get_color()); np.set_text(s.get_text()); temp.add_process(np); h.set_size(h.get_size() - s.get_size()); h.set_start_location(h.get_start_location() + s.get_size()); success = 1; break; } } if (success == 0) { MessageBox.Show("Process cannot be added to memory"); return; } } memory = temp; lst_memory.Controls.Clear(); memory_draw(); /*if added successfully remove the process from wait list*/ b.Enabled = false; lbl.Enabled = false; b.Hide(); lbl.Hide(); /**END OF FIRST FIT*/ } else if (bestfit.Checked == true) { memory temp = memory; bool check = false; List <bool> x = new List <bool>(); for (int i = 0; i < temp.get_number_holes_after_merge(); i++) { x.Add(true); } temp.arrange_memory_ascending_size(); foreach (segment s in p.get_segments()) { int i = 0; foreach (hole h in temp.get_holes()) { if (x[i]) { if (s.get_size() > h.get_size()) { check = false; continue; } else { x[i] = false; check = true; break; } } i++; } } if (check) { foreach (segment s in p.get_segments()) { foreach (hole h in temp.get_holes()) { if (s.get_size() > h.get_size()) { continue; } else { hole get_in = new hole(s.get_size(), h.get_start_location()); get_in.set_color(s.get_color()); get_in.set_text(s.get_text()); h.set_size(h.get_size() - s.get_size()); h.set_start_location(h.get_start_location() + s.get_size()); temp.add_process(get_in); break; } } } temp.merge_holes(); } else { MessageBox.Show("Process cannot be added to memory"); return; } memory = temp; lst_memory.Controls.Clear(); memory_draw(); b.Enabled = false; lbl.Enabled = false; b.Hide(); lbl.Hide(); } else if (worstfit.Checked == true) { memory temp = memory; bool check = false; List <bool> x = new List <bool>(); for (int i = 0; i < temp.get_number_holes_after_merge(); i++) { x.Add(true); } temp.arrange_memory_descending_size(); foreach (segment s in p.get_segments()) { int i = 0; foreach (hole h in temp.get_holes()) { if (x[i]) { if (s.get_size() > h.get_size()) { check = false; continue; } else { x[i] = false; check = true; break; } } i++; } } if (check) { foreach (segment s in p.get_segments()) { foreach (hole h in temp.get_holes()) { if (s.get_size() > h.get_size()) { continue; } else { hole get_in = new hole(s.get_size(), h.get_start_location()); get_in.set_color(s.get_color()); get_in.set_text(s.get_text()); h.set_size(h.get_size() - s.get_size()); h.set_start_location(h.get_start_location() + s.get_size()); temp.add_process(get_in); break; } } } temp.merge_holes(); } else { MessageBox.Show("Process cannot be added to memory"); return; } memory = temp; lst_memory.Controls.Clear(); memory_draw(); b.Enabled = false; lbl.Enabled = false; b.Hide(); lbl.Hide(); } }