public Form6(List <process> p, memory m) { InitializeComponent(); processes = p; memory = m; memory.calulate_memory_processes(); }
public memory copy() { memory other = new memory(get_size(), get_number_holes_after_merge()); List <hole> tholes = new List <hole>(); foreach (hole h in holes) { hole nh = new hole(h.get_size(), h.get_start_location(), h.get_end_location(), h.get_color(), h.get_text()); tholes.Add(nh); } List <hole> tpro = new List <hole>(); foreach (hole h in processes) { hole nh = new hole(h.get_size(), h.get_start_location(), h.get_end_location(), h.get_color(), h.get_text()); tpro.Add(nh); } other.set_holes(tholes); other.set_processes(tpro); return(other); }
private void btn_to_form5_Click(object sender, EventArgs e) { string s = txt_memory_size.Text; int test; if (s == null || int.TryParse(s, out test) == false || int.Parse(s) == 0) { MessageBox.Show("enter a valid number"); return; } s = txt_number_of_holes.Text; if (s == null || int.TryParse(s, out test) == false || int.Parse(s) <= 0) { MessageBox.Show("enter a valid number"); return; } memory memory = new memory(int.Parse(txt_memory_size.Text), int.Parse(txt_number_of_holes.Text)); Form5 frm = new Form5(memory, processes); Visible = false; frm.ShowDialog(); Close(); }
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(); } }
public Form5(memory m, List <process> p) { InitializeComponent(); memory = m; processes = p; }