Exemplo n.º 1
0
        //CONSTRUCTOR
        /*TODO(get buddySystem List through constructor) constructor with parameters is somehow not possible. give buddySystem List to constructor*/
        public BuddySystemViewCell()
        {
            //note: List<BuddySystemBlock> buddySystem  = BuddySystem.buddySystem would not copy the list
            //note: buddySystem = new List<BuddySystemBlock>(BuddySystem.buddySystem); would not create new references
            //since the paintsurface method get's called several times, even after the object was created,
            //there has to be a constant copy of the original list at the time
            //and since the upper way of copying the list keeps the same references to the original buddysystemblock objects
            //it has to be copied manually
            List <BuddySystemBlock> original = new List <BuddySystemBlock>(BuddySystem.buddySystem);

            buddySystem = new List <BuddySystemBlock>();
            for (int i = 0; i < original.Count; i++)
            {
                BuddySystemBlock b = new BuddySystemBlock(
                    original[i].GetBlockSize(),
                    original[i].GetBuddyNo());

                if (original[i].GetFree() == false)
                {
                    b.OccupyBlock(
                        original[i].GetProcessName(),
                        original[i].GetProcessSize());
                }
                buddySystem.Add(b);
            }

            this.processName = BuddySystem.currentProcess;
            this.endProcess  = BuddySystem.endProcess;

            // crate the canvas
            skiaview = new SKCanvasView();
            skiaview.PaintSurface += PaintSurface;

            //changing background color for better clarity
            if (dari % 2 == 0)
            {
                skiaview.BackgroundColor = App._viewBackground;
            }
            else
            {
                skiaview.BackgroundColor = App._viewBackground;
            }
            dari++;

            // assign the canvas to the cell
            this.View = skiaview;
        }
Exemplo n.º 2
0
        /**********************************************************************
         *********************************************************************/
        //splits the block at the index until it has the required size
        public static void SplitBlock(int index, int requiredSize)
        {
            int blockSize = buddySystem[index].GetBlockSize();

            //entferne Block an Index in der Liste
            //Teile in zwei auf, solange bis blocksize = requiredsize entspricht
            while (blockSize > requiredSize)
            {
                int dummy = blockSize / 2;
                if (dummy >= requiredSize)
                {
                    //split
                    List <int> buddyNoList = buddySystem[index].GetBuddyNoList();
                    buddySystem.Remove(buddySystem[index]);
                    BuddySystemBlock block1 = new BuddySystemBlock(dummy, 2);
                    BuddySystemBlock block2 = new BuddySystemBlock(dummy, 1);
                    block1.SetBuddyNoList(buddyNoList);
                    block2.SetBuddyNoList(buddyNoList);
                    buddySystem.Insert(index, block1);
                    buddySystem.Insert(index, block2);
                }
                blockSize = dummy;
            }
        }