Ejemplo n.º 1
0
        private static void Free(Cell cell)
        {
            for (int j = 0; j < cell.Size; j++)
            {
                memory[cell.StartIndex + j] = 0;
            }

            ReShuffle();
        }
Ejemplo n.º 2
0
        private static void FillSector(Cell cell, int index)
        {
            cell.StartIndex = index;

            for (int j = 0; j < cell.Size; j++)
            {
                memory[index + j] = cell.Value;
            }
        }
Ejemplo n.º 3
0
        private static bool IsEnoughtSpace(Cell cell, int startIndex)
        {
            for (int sizeIndex = 0; sizeIndex < cell.Size; sizeIndex++)
            {
                if (memory[startIndex + sizeIndex] != 0)
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 4
0
        private static void Main(string[] args)
        {
            while (true)
            {
                Thread.Sleep(random.Next(500, 1000));

                Cell cell = new Cell(random.Next(1, 10),random.Next(10, 200));

                Thread thread = new Thread(delegate()
                {
                    Tr(cell);
                });
                thread.Start();
            }
        }
Ejemplo n.º 5
0
        private static void Alloc(Cell cell)
        {
            for (int index = 0; index < memory.Length; index++)
            {
                if (memory.Length < (index + cell.Size))
                {
                    break;
                }

                if (memory[index] == 0)
                {
                    if (IsEnoughtSpace(cell, index))
                    {
                        FillSector(cell, index);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static void Tr(Cell cell)
        {
            Alloc(cell);

            ShowMemory();
            Thread.Sleep(2000);

            Free(cell);
        }