Пример #1
0
        public bool FeedProcess(Process proc)
        {
            bool response = false;

            if (proc.Type == "Allocate")
            {
                ProcessAllocateEventArgs arg = new ProcessAllocateEventArgs();
                response = AllocateProcess(proc, out arg);

                if (response == true)
                {
                    OnAllocated(arg);
                }
            }
            else if (proc.Type == "DeAllocate")
            {
                ProcessDeAllocateEventArgs arg = new ProcessDeAllocateEventArgs();
                response = DeAllocateProcess(proc, out arg);

                if (response == true)
                {
                    OnDeAllocated(arg);
                }
            }

            return(false);
        }
Пример #2
0
        public override bool DeAllocateProcess(Process proc, out ProcessDeAllocateEventArgs arg)
        {
            bool isEnd       = false;
            int  startIndex  = 0;
            int  blockLength = 0;

            for (int i = 0; i < MemorySize; i++)
            {
                if (Memory[i].ProcessId == proc.ID && Memory[i].IsStart == true)
                {
                    startIndex = i;
                }

                if (Memory[i].ProcessId == proc.ID && Memory[i].IsEnd == true)
                {
                    blockLength = i - startIndex;

                    isEnd = true;
                }

                if (Memory[i].ProcessId == proc.ID)
                {
                    Memory[i].IsAssigned = false;
                    Memory[i].IsEnd      = false;
                    Memory[i].IsStart    = false;
                    Memory[i].ProcessId  = 0;
                }

                if (isEnd)
                {
                    break;
                }
            }

            for (int i = Processes.Count - 1; i > 0; i--)
            {
                if (Processes[i].ID == proc.ID)
                {
                    Processes.RemoveAt(i);
                }
            }
            arg = new ProcessDeAllocateEventArgs {
                ProcessID = proc.ID, ProcessName = proc.Name, StartBlock = startIndex, BlockLength = blockLength
            };

            return(true);
        }
Пример #3
0
 public abstract bool DeAllocateProcess(Process objProcess, out ProcessDeAllocateEventArgs arg);
Пример #4
0
        public override bool DeAllocateProcess(Process proc, out ProcessDeAllocateEventArgs arg)
        {
            // modifies memory
            bool isEnd       = false;
            int  startIndex  = 0;
            int  blockLength = 0;

            for (int i = 0; i < MemorySize; i++)
            {
                if (Memory[i].ProcessId == proc.ID && Memory[i].IsStart == true)
                {
                    startIndex = i;
                }

                if (Memory[i].ProcessId == proc.ID && Memory[i].IsEnd == true)
                {
                    blockLength = i - startIndex;

                    isEnd = true;
                }

                if (Memory[i].ProcessId == proc.ID)
                {
                    Memory[i].IsAssigned = false;
                    Memory[i].IsEnd      = false;
                    Memory[i].IsStart    = false;
                    Memory[i].ProcessId  = 0;
                }

                if (isEnd)
                {
                    break;
                }
            }

            // finds and removes the target process
            for (int i = Processes.Count - 1; i > 0; i--)
            {
                if (Processes[i].ID == proc.ID)
                {
                    Processes.RemoveAt(i);
                }
            }

            arg = new ProcessDeAllocateEventArgs
            {
                ProcessID   = proc.ID,
                ProcessName = proc.Name
            };

            // converts the allocated data to available data
            BlockFit b = null;

            for (int i = 0; i < allocated.Count; i++)
            {
                b = allocated[i];
                if (b.ID == proc.ID)
                {
                    arg.StartBlock  = b.start_pos;
                    arg.BlockLength = b.blockLength;

                    allocated.Remove(allocated[i]);
                    for (int j = 0; j < avail.Count; j++)
                    {
                        // if the newly available blocks are next to already existing available blocks, merge them
                        BlockFit bl = avail[j];
                        if (b.start_pos + b.blockLength - 1 == bl.start_pos)
                        {
                            b = new BlockFit()
                            {
                                ID = bl.ID, blockLength = b.blockLength + bl.blockLength, start_pos = b.start_pos
                            };
                            avail.Remove(avail[j]);
                        }
                        if (bl.start_pos + bl.blockLength - 1 == b.start_pos)
                        {
                            b = new BlockFit()
                            {
                                blockLength = b.blockLength + bl.blockLength, start_pos = bl.start_pos
                            };
                            avail.Remove(avail[j]);
                        }
                    }
                    avail.Add(b);

                    break;
                }
            }
            return(true);
        }