예제 #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);
        }
예제 #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);
        }