Esempio n. 1
0
        public override AllocState Alloc(string jobName, int size)
        {
            if (size > MemRest)
            {
                return new AllocState {
                           OutOfMemory = true
                }
            }
            ;
            if (!this.All(_ => _.Name != jobName))
            {
                return new AllocState {
                           IsJobExist = true
                }
            }
            ;

            var toAlloc = FreeList.FirstOrDefault(_ => _.Size >= size);

            if (toAlloc != null)
            {
                toAlloc.Name = jobName;

                MemRest -= toAlloc.Size;
                return(new AllocState {
                    Success = true
                });
            }
            return(new AllocState {
                NoAvailableUnit = true
            });
        }
Esempio n. 2
0
        public override AllocState Alloc(string jobName, int size)
        {
            if (size > MemRest)
            {
                return new AllocState {
                           OutOfMemory = true
                }
            }
            ;
            if (!this.All(_ => _.Name != jobName))
            {
                return new AllocState {
                           IsJobExist = true
                }
            }
            ;

            MemoryBlock mem = null;

            if (Mode == Modes.BF)
            {   //对空闲分区按容量进行升序排序,选择首个能容纳进程的分区分配给进程
                mem = FreeList.OrderBy(_ => _.Size).FirstOrDefault(_ => _.Size >= size);
            }
            else
            {   //从空闲分区中将第一个能容纳进程的分区分配给进程
                mem = FreeList.FirstOrDefault(_ => _.Size >= size);
            }
            var memIndex = IndexOf(mem);

            if (memIndex < 0)
            {
                return new AllocState {
                           NoAvailableUnit = true
                }
            }
            ;
            if ((mem.Size -= size) == 0)
            {
                Remove(mem);
            }
            Insert(memIndex, new MemoryBlock(jobName, size));
            MemRest -= size;
            return(new AllocState {
                Success = true
            });
        }