Пример #1
0
        public static List <memoryitem> WorstFit(process newprocess) //approved
        {
            process           nprocess = newprocess;
            List <memoryitem> temp     = memory;

            temp = memory.OrderByDescending(d => d.getsize()).ToList();
            foreach (var item in temp)
            {
                if (item.type == "h")
                {
                    if (item.size >= newprocess.size)
                    {
                        int startaddress = item.getstratingadd();
                        int size         = item.getsize();
                        nprocess.setstarting_add(startaddress);
                        memory.Add(nprocess);
                        hole nhole = new hole((startaddress + nprocess.getsize()), (size - nprocess.getsize()));
                        memory.Add(nhole);
                        memory.Remove(item);
                        allprocess.Add(nprocess);
                        break;
                    }
                }
            }
            concatenate(memory);
            return(memory);
        }
Пример #2
0
        public static List <memoryitem> BestFit(process newprocess)
        {
            process           nprocess = newprocess;
            List <memoryitem> temp     = memory;

            temp = memory.OrderBy(a => a.getsize()).ToList();

            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);
        }
Пример #3
0
        public static void concatenate(List <memoryitem> L) // approved
        {
            List <memoryitem> temp  = L;
            List <memoryitem> holes = new List <memoryitem>();
            hole h = new hole();

            foreach (var item in temp)
            {
                if (item.type == "h")
                {
                    holes.Add(item);
                }
            }
            holes = holes.OrderBy(add => add.getstratingadd()).ToList();
            for (int i = 0; i < holes.Count - 1; i++)
            {
                int size1 = holes[i].getsize();
                int size2 = holes[i + 1].getsize();
                int add1  = holes[i].getstratingadd();
                int add2  = holes[i + 1].getstratingadd();
                if (add1 + size1 == add2)
                {
                    L.Remove(holes[i]);
                    L.Remove(holes[i + 1]);
                    h.setsize(size1 + size2);
                    h.setstarting_add(add1);
                    L.Add(h);
                }
            }
        }
Пример #4
0
        public static void blackbox(hole hole)
        {
            List <memoryitem> temp = memory.OrderBy(a => a.getstratingadd()).ToList();
            memoryitem        last_item;
            int st_add;
            int t_size;

            if (temp.Count > 0)
            {
                last_item = temp.Last();
                t_size    = last_item.size;
                st_add    = last_item.getstratingadd();
                if ((st_add + t_size < hole.starting_add))
                {
                    blackhole before = new blackhole(st_add + t_size, (hole.starting_add - st_add - t_size));
                    memory.Add(before);
                }
            }
        }
Пример #5
0
        public static List <memoryitem> deallocate(string processname)
        {
            string name = processname;

            foreach (var item in memory)
            {
                if (item.type == "p" && item.getname() == name)
                {
                    int size    = item.getsize();
                    int address = item.getstratingadd();
                    memory.Remove(item);
                    allprocess.Remove(item);
                    hole nhole = new hole((address), (size));
                    memory.Add(nhole);
                    break;
                }
            }
            concatenate(memory);
            return(memory);
        }
Пример #6
0
        public static void inserthole(hole hole)
        {
            foreach (var item in memory)
            {
                if (item.type == "s")
                {
                    if ((item.starting_add + item.size <= hole.getstratingadd()))
                    {
                        continue;
                    }
                    else if ((item.starting_add <= hole.getstratingadd()) && (item.starting_add + item.size > hole.getstratingadd()))
                    {
                        int starting_add = item.starting_add;
                        int size_temp    = item.size;

                        blackhole before = new blackhole(starting_add, (hole.starting_add - starting_add));
                        blackhole after  = new blackhole(hole.starting_add + hole.size, starting_add + size_temp - hole.starting_add - hole.size);
                        memory.Remove(item);
                        memory.Add(hole);
                        memory.Add(before);
                        memory.Add(after);
                        return;
                    }
                    else if ((item.starting_add <= hole.getstratingadd()) && (item.starting_add + item.size < hole.getstratingadd() + hole.size))
                    {
                    }
                }
                else if (item.type == "p")
                {
                    if ((item.starting_add + item.size <= hole.getstratingadd()))
                    {
                        continue;
                    }
                    else if ((item.starting_add <= hole.getstratingadd()) && (item.starting_add + item.size > hole.getstratingadd()))
                    {
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    if ((item.starting_add + item.size <= hole.getstratingadd()))
                    {
                        continue;
                    }
                    else if ((item.starting_add <= hole.getstratingadd()) && (item.starting_add + item.size >= hole.getstratingadd()))
                    {
                        return;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            blackbox(hole);
            memory.Add(hole);
            concatenate(memory);
        }