Exemplo n.º 1
0
        public static List <memoryitem> WorstFit(process newprocess, List <memoryitem> memory) //approved
        {
            process           nprocess = newprocess;
            List <memoryitem> temp     = memory;

            temp.OrderByDescending(d => d.getsize());
            foreach (var item in temp)
            {
                if (item.type == "h")
                {
                    if (item.size >= newprocess.size)
                    {
                        //get el starting address w el size
                        int startaddress = item.getstratingadd();
                        int size         = item.getsize();
                        //add new process in pos (starting address)
                        nprocess.setstarting_add(startaddress);
                        memory.Add(nprocess);
                        //add new hole in pos start address+size of process its size equals ( old hole size - new process size)
                        hole nhole = new hole((startaddress + nprocess.getsize()), (size - nprocess.getsize()));
                        memory.Add(nhole);
                        //delete el hole el adema
                        memory.Remove(item);
                        allprocess.Add(nprocess);
                        break;
                    }
                }
            }
            concatenate(memory);
            return(memory);
        }
Exemplo n.º 2
0
        public static List <memoryitem> FirstFit(process newprocess, List <memoryitem> memory) //approved
        {
            process nprocess = newprocess;

            foreach (var item in memory)
            {
                if (item.type == "h")
                {
                    if (item.size >= newprocess.size)
                    {
                        //get el starting address w el size
                        int startaddress = item.getstratingadd();
                        int size         = item.getsize();
                        //add new process in pos (starting address)
                        nprocess.setstarting_add(startaddress);
                        memory.Add(nprocess);
                        //add new hole in pos start address+size of process its size equals ( old hole size - new process size)
                        hole nhole = new hole((startaddress + nprocess.getsize()), (size - nprocess.getsize()));
                        memory.Add(nhole);
                        //delete el hole el adema
                        memory.Remove(item);
                        allprocess.Add(nprocess);
                        break;
                    }
                    //else Console.WriteLine("Process {0} is aded to waiting queue.", nprocess.getname());
                }
            }
            concatenate(memory);
            return(memory);
        }
Exemplo n.º 3
0
        void best_fit(string process_name)
        {
            warning = false;
            process p1 = new process(process_counter.ToString(), process_name);

            for (int i = 0; i < temp_seg_list.Count; i++)
            {
                p1.process_segments.Add(temp_seg_list[i]);
            }
            process_counter++;

            double min_size  = -1;
            int    min_index = -1;

            for (int j = 0; j < temp_seg_list.Count; j++)
            {
                min_size  = -1;
                min_index = -1;
                for (int i = 0; i < h_list.Count; i++)
                {
                    if (temp_seg_list[j].size <= h_list[i].size)
                    {
                        if (min_size == -1 || min_size > h_list[i].size)
                        {
                            min_size  = h_list[i].size;
                            min_index = i;
                        }
                    }
                }
                if (min_size == -1)
                {
                    warning = true;
                    MessageBox.Show("Not enough space for input process!", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    switch_seg_table(true);
                    temp_seg_list.Clear();
                    return;
                }
                temp_seg_list[j].start  = h_list[min_index].start;
                h_list[min_index].start = h_list[min_index].start + temp_seg_list[j].size;
                h_list[min_index].size -= temp_seg_list[j].size;
                if (h_list[min_index].size == 0)
                {
                    h_list.RemoveAt(min_index);
                }
            }
            for (int i = 0; i < temp_seg_list.Count; i++)
            {
                seg_list.Add(temp_seg_list[i]);
            }
            p_list.Add(p1);
            //temp_seg_list.Clear();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            hole    h1 = new hole(50, 220);
            hole    h2 = new hole(300, 100);
            hole    h3 = new hole(560, 140);
            hole    h4 = new hole(700, 80);
            process p1 = new process("p1", 150);
            process p2 = new process("p2", 130);
            process p3 = new process("p3", 270);
            process p4 = new process("p4", 50);
            process p5 = new process("p5", 180);
            process p6 = new process("p6", 90);

            List <memoryitem> x = new List <memoryitem>();

            x.Add(h1); x.Add(h2); x.Add(h3); x.Add(h4);

            //MemoryAllocation.methodology.FirstFit(p1, x);
            //MemoryAllocation.methodology.FirstFit(p2, x);
            //MemoryAllocation.methodology.FirstFit(p3, x);
            //MemoryAllocation.methodology.FirstFit(p4, x);
            //MemoryAllocation.methodology.FirstFit(p5, x);
            //MemoryAllocation.methodology.FirstFit(p6, x);
            //MemoryAllocation.methodology.deallocate("p4", x);

            MemoryAllocation.methodology.BestFit(p1, x);
            MemoryAllocation.methodology.BestFit(p2, x);
            MemoryAllocation.methodology.BestFit(p3, x);
            MemoryAllocation.methodology.BestFit(p4, x);
            MemoryAllocation.methodology.BestFit(p5, x);
            MemoryAllocation.methodology.BestFit(p6, x);

            //MemoryAllocation.methodology.WorstFit(p1, x);
            //MemoryAllocation.methodology.WorstFit(p2, x);
            //MemoryAllocation.methodology.WorstFit(p3, x);
            //MemoryAllocation.methodology.WorstFit(p4, x);
            //MemoryAllocation.methodology.WorstFit(p5, x);
            //MemoryAllocation.methodology.WorstFit(p6, x);

            foreach (var item in x)
            {
                Console.Write(item.getstratingadd());
                Console.WriteLine();
                Console.Write(item.getsize());
                Console.WriteLine();
            }
        }
Exemplo n.º 5
0
        void first_fit(string process_name)
        {
            warning = false;
            bool    flag = true;
            process p1   = new process(process_counter.ToString(), process_name);

            for (int i = 0; i < temp_seg_list.Count; i++)
            {
                p1.process_segments.Add(temp_seg_list[i]);
            }
            process_counter++;
            for (int j = 0; j < temp_seg_list.Count; j++)
            {
                for (int i = 0; i < h_list.Count; i++)
                {
                    if (temp_seg_list[j].size <= h_list[i].size)
                    {
                        flag = false;
                        temp_seg_list[j].start = h_list[i].start;
                        h_list[i].start        = h_list[i].start + temp_seg_list[j].size;
                        h_list[i].size        -= temp_seg_list[j].size;
                        break;
                    }
                }
                if (flag == true)
                {
                    warning = true;
                    MessageBox.Show("Not enough space for input process!", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    switch_seg_table(true);
                    temp_seg_list.Clear();
                    return;
                }
                flag = true;
            }
            for (int i = 0; i < temp_seg_list.Count; i++)
            {
                seg_list.Add(temp_seg_list[i]);
            }
            p_list.Add(p1);
            //temp_seg_list.Clear();
        }
Exemplo n.º 6
0
        void startingSegments(double memory_size, List <hole> holes)
        {
            double start, range;
            double current = 0;

            for (int i = 0; i < holes.Count(); i++)
            {
                start = holes[i].start;
                range = holes[i].size;
                if (current < start)
                {
                    segment s = new segment(start - current, "0", "Segment");
                    s.start = current;
                    seg_list.Add(s);
                    temp_seg_list.Add(s);
                    current = start + range;
                }
                else
                {
                    current = start + range;
                }
            }
            if (current < memory_size)
            {
                segment s = new segment(memory_size - current, "0", "Segment");
                s.start = current;
                seg_list.Add(s);
                temp_seg_list.Add(s);
            }
            for (int i = 0; i < temp_seg_list.Count; i++)
            {
                process p0 = new process(process_counter.ToString(), "Initially allocated " + (i + 1));
                temp_seg_list[i].code = process_counter.ToString();
                p_list.Add(p0);
                process_counter++;
            }
        }