Ejemplo n.º 1
0
        public void worst_Fit()
        {
            MyMemory_Allocated = new LinkedList <memory>(MyMemory_Allocated.OrderByDescending(item => item.Size));
            for (int i = 0; i < MyMemory_Allocated.Count; i++)
            {
                LinkedListNode <memory> hole_node = MyMemory_Allocated.First;
                memory hole1   = MyMemory_Allocated.ElementAt(i);
                memory process = new memory();
                if (Convert.ToInt32(process_size) <= hole1.Size && hole1.IsProcess == false)
                {
                    process.name        = "P" + memory_Id;
                    process.Size        = Convert.ToInt32(process_size);
                    process.BaseAddress = hole1.BaseAddress;
                    process.IsProcess   = true;
                    hole1.BaseAddress  += Convert.ToInt32(process_size);
                    hole1.Size         -= Convert.ToInt32(process_size);
                    MyMemory_Allocated.AddBefore(hole_node, process);
                    if (hole1.Size == 0)
                    {
                        MyMemory_Allocated.Remove(hole1);
                    }
                    draw_process();

                    break;
                }

                hole_node = MyMemory_Allocated.First.Next;
            }
        }
Ejemplo n.º 2
0
        public void drawHoles()
        {
            dataGridView1.ColumnCount     = 1;
            dataGridView1.Columns[0].Name = "Memory allocation " + memory_Id;
            MyMemory = new LinkedList <memory>(MyMemory.OrderBy(item => item.BaseAddress));
            //concatenation of holes
            for (int i = 0; i < MyMemory.Count(); i++)
            {
                for (int j = 0; j < MyMemory.Count() - 1; j++)
                {
                    if (MyMemory.ElementAt(j + 1).BaseAddress <= MyMemory.ElementAt(j).BaseAddress + MyMemory.ElementAt(j).Size)
                    {
                        if (MyMemory.ElementAt(j + 1).BaseAddress + MyMemory.ElementAt(j + 1).Size <= MyMemory.ElementAt(j).BaseAddress + MyMemory.ElementAt(j).Size)
                        {
                            MyMemory.ElementAt(j).Size = MyMemory.ElementAt(j).Size;
                        }
                        else
                        {
                            MyMemory.ElementAt(j).Size = MyMemory.ElementAt(j + 1).Size + MyMemory.ElementAt(j + 1).BaseAddress - MyMemory.ElementAt(j).BaseAddress;
                        }
                        var current_node = MyMemory.ElementAt(j + 1);
                        MyMemory.Remove(current_node);
                    }
                }
            }

            dataGridView1.RowCount = MyMemory.Count();

            MyMemory = new LinkedList <memory>(MyMemory.OrderBy(item => item.BaseAddress));
            for (int i = 0; i < MyMemory.Count(); i++)
            {
                MyMemory.ElementAt(i).name                       = "H" + i;
                dataGridView1.Rows[i].Cells[0].Value             = MyMemory.ElementAt(i).name + "\n" + "BA= " + MyMemory.ElementAt(i).BaseAddress + "\n" + "Size= " + MyMemory.ElementAt(i).Size;
                dataGridView1.Rows[i].Height                     = Convert.ToInt32((MyMemory.ElementAt(i).Size) * 0.15 + 50);
                dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
                dataGridView1.Rows[i].Cells[0].Selected          = false;
            }
            for (int i = 0; i < MyMemory.Count; i++)
            {
                memory m1 = new memory();
                m1.name        = MyMemory.ElementAt(i).name;
                m1.Size        = MyMemory.ElementAt(i).Size;
                m1.BaseAddress = MyMemory.ElementAt(i).BaseAddress;
                m1.IsProcess   = MyMemory.ElementAt(i).IsProcess;
                MyMemory_Allocated.AddLast(m1);
            }
        }
Ejemplo n.º 3
0
 private void ClearMemory_Click(object sender, EventArgs e)
 {
     memory_Id = 0;
     dataGridView1.ColumnCount     = 1;
     dataGridView1.Columns[0].Name = "Memory allocation " + memory_Id;
     dataGridView1.RowCount        = MyMemory.Count();
     for (int i = 0; i < MyMemory.Count(); i++)
     {
         MyMemory.ElementAt(i).name                       = "H" + i;
         dataGridView1.Rows[i].Cells[0].Value             = MyMemory.ElementAt(i).name + "\n" + "BA= " + MyMemory.ElementAt(i).BaseAddress + "\n" + "Size= " + MyMemory.ElementAt(i).Size;
         dataGridView1.Rows[i].Height                     = Convert.ToInt32((MyMemory.ElementAt(i).Size) * 0.15 + 50);
         dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
     }
     MyMemory_Allocated.Clear();
     for (int i = 0; i < MyMemory.Count; i++)
     {
         memory m1 = new memory();
         m1.name        = MyMemory.ElementAt(i).name;
         m1.Size        = MyMemory.ElementAt(i).Size;
         m1.BaseAddress = MyMemory.ElementAt(i).BaseAddress;
         m1.IsProcess   = MyMemory.ElementAt(i).IsProcess;
         MyMemory_Allocated.AddLast(m1);
     }
 }