示例#1
0
        public static bool UnitTest(int seed)
        {
            Random                      random      = new Random(seed);
            int                         totalBytes  = 256 * 1024;
            MemoryAllocation            memory      = new MemoryAllocation(totalBytes);
            List <MemoryBlockByAddress> allocations = new List <MemoryBlockByAddress>();

            for (int i = 20 * 1000; --i >= 0;)
            {
                bool allocate = allocations.Count == 0 || (memory.FreeBytes > 0 && random.Next(2) == 0);
                if (allocate)
                {
                    allocations.Add(memory.Allocate(1 + random.Next((int)memory.FreeBytes)));
                }
                else
                {
                    int index = random.Next(allocations.Count);
                    memory.Free(allocations[index]);
                    allocations.RemoveAt(index);
                }
            }
            foreach (var item in allocations)
            {
                memory.Free(item);
            }
            if (memory.AllocatedBlocksCount != 0 || memory.FreeBlocksCount != 1 || memory.FreeBytes != totalBytes)
            {
                return(false);
            }
            return(true);
        }
示例#2
0
 public void ApplyConfiguration()
 {
     this.memory = new MemoryAllocation(this.MemorySizeKB << 10);
     this.Input.Apply(this.SubregisterIsFloatingPoint != 0, this.SubregistersPerRegister, this.NumberOfInputRealRegisters, this.NumberOfInputComplexRegisters);
     this.Output.Apply(this.SubregisterIsFloatingPoint != 0, this.SubregistersPerRegister, this.NumberOfOutputRealRegisters, this.NumberOfOutputComplexRegisters);
     this.Work.Apply(this.SubregisterIsFloatingPoint != 0, this.SubregistersPerRegister, this.NumberOfRealRegisters, this.NumberOfComplexRegisters);
 }