public PartitionRecord getPartition(AllocateAction allocation) { int PartitionsCount = simulatorModel.Partitions.Count; LastIndex = simulatorModel.Partitions.IndexOf(getPartitionByMemoryAddress(lastGeneratedUserMemoryAddress)); if (LastIndex > PartitionsCount || LastIndex < 0) LastIndex = 0; for (int i = LastIndex; i < PartitionsCount; i++) { if (simulatorModel.Partitions.ElementAt(i).PartitionType == PartitionType.Free) { if (simulatorModel.Partitions.ElementAt(i).Size >= allocation.RequiredSize) { LastGeneratedUserMemoryAddress = generateUserMemoryAddress(simulatorModel.Partitions.ElementAt(i)); return simulatorModel.Partitions.ElementAt(i); } } } for (int i = 0; i < LastIndex; i++) { if (simulatorModel.Partitions.ElementAt(i).PartitionType == PartitionType.Free) { if (simulatorModel.Partitions.ElementAt(i).Size >= allocation.RequiredSize) { LastGeneratedUserMemoryAddress = generateUserMemoryAddress(simulatorModel.Partitions.ElementAt(i)); return simulatorModel.Partitions.ElementAt(i); } } } return null; }
private void AllocateSpaceOnPartition(PartitionRecord freePartitionToUse, AllocateAction allocateAction) { int partitionIndex = Partitions.IndexOf(freePartitionToUse); int difference = freePartitionToUse.Size - allocateAction.RequiredSize; Partitions.RemoveAt(partitionIndex); if (difference > 0) { Partitions.Insert(partitionIndex, new PartitionRecord(freePartitionToUse.Size - allocateAction.RequiredSize)); } Partitions.Insert(partitionIndex, new PartitionRecord(allocateAction.RequiredSize, allocateAction.AllocatedNewSpaceId)); }