Ejemplo n.º 1
0
        /**********************************************************************
         *********************************************************************/
        private static void DrawRedArrow(float relativeFragmentSize)
        {
            // determine position of fragment block
            int index = AllocationStrategiesAlgorithm.GetCurrentIndex(); //TODO: nach merge könnte der index nicht mehr existieren
            List <FragmentBlock> allFragmentsList = AllocationStrategiesAlgorithm.GetAllFragmentsList();
            float mX1 = 0.1f;                                            // memory bound x1

            int           stepsSoFar = 0;
            FragmentBlock fragment   = null;

            for (int i = 0; i <= index; i++)
            {
                fragment    = allFragmentsList.ElementAt(i);
                stepsSoFar += fragment.GetSize();
            }
            float fragmentStart = mX1 + (stepsSoFar * relativeFragmentSize) - (fragment.GetSize() * relativeFragmentSize);
            float fragmentEnd   = mX1 + (stepsSoFar * relativeFragmentSize);
            float xPosition     = fragmentEnd - (fragmentEnd - fragmentStart) / 2; // position of text in the middle of fragment

            // draw the arrow
            float arrowTip = 0.275f;

            canvas.DrawLine(xPercent(xPosition), yPercent(arrowTip - 0.125f), xPercent(xPosition), yPercent(arrowTip), sk_ArrowRed);
            SKPath arrow = new SKPath();

            arrow.MoveTo(xPercent(xPosition), yPercent(arrowTip));
            arrow.RLineTo(yPercent(0.015f), -yPercent(0.03f));
            arrow.RLineTo(-yPercent(0.03f), 0);
            arrow.RLineTo(yPercent(0.015f), yPercent(0.03f));
            arrow.Close();
            canvas.DrawPath(arrow, sk_ArrowRed);
        }
Ejemplo n.º 2
0
        /**********************************************************************
         ***********************************************************************
         * creates a list of all free fragment indexes in the order they are going to be processed by the algorithm*/
        public static List <int> UpdateFreeFragmentsIndexSequenceList(List <FragmentBlock> p_AllFragmentsList)
        {
            int numberOfFragments = p_AllFragmentsList.Count();

            freeFragmentsIndexSequenceList.Clear();


            // go from index i to end of list
            for (int i = indexLastAllocated; i < numberOfFragments; i++)
            {
                FragmentBlock fb = p_AllFragmentsList.ElementAt(i);
                if (fb.IsFree())
                {
                    freeFragmentsIndexSequenceList.Add(i);
                }
            }
            // go from start of list to index i
            for (int i = 0; i < indexLastAllocated; i++)
            {
                FragmentBlock fb = p_AllFragmentsList.ElementAt(i);
                if (fb.IsFree())
                {
                    freeFragmentsIndexSequenceList.Add(i);
                }
            }

            return(freeFragmentsIndexSequenceList);
        }
Ejemplo n.º 3
0
        /**********************************************************************
         *********************************************************************/
        private static void DrawGrayArrow(int index, float relativeFragmentSize)
        {
            // determine position of fragment block
            List <FragmentBlock> allFragmentsList = AllocationStrategiesAlgorithm.GetAllFragmentsList();
            float mX1 = 0.1f; // memory bound x1

            int           stepsSoFar = 0;
            FragmentBlock fragment   = null;

            for (int i = 0; i <= index; i++)
            {
                fragment    = allFragmentsList.ElementAt(i);
                stepsSoFar += fragment.GetSize();
            }
            float fragmentStart = mX1 + (stepsSoFar * relativeFragmentSize) - (fragment.GetSize() * relativeFragmentSize);
            float fragmentEnd   = mX1 + (stepsSoFar * relativeFragmentSize);
            float xPosition     = fragmentEnd - (fragmentEnd - fragmentStart) / 2; // position of text in the middle of fragment


            // draw the arrow
            float arrowTip = 0.725f;

            canvas.DrawLine(xPercent(xPosition), yPercent(arrowTip + 0.125f), xPercent(xPosition), yPercent(arrowTip), sk_ArrowGray);
            SKPath arrow = new SKPath();

            arrow.MoveTo(xPercent(xPosition), yPercent(arrowTip));
            arrow.RLineTo(-yPercent(0.015f), +yPercent(0.03f));
            arrow.RLineTo(+yPercent(0.03f), 0);
            arrow.RLineTo(-yPercent(0.015f), -yPercent(0.03f));
            arrow.Close();
            canvas.DrawPath(arrow, sk_ArrowGray);
        }
Ejemplo n.º 4
0
        /**********************************************************************
         ***********************************************************************/
        public static void MergeUsedFragments(int index)
        {
            int i = index;

            if (i >= allFragmentsList.Count())
            {
                status = Status.merged;
            }
            else if (allFragmentsList.ElementAt(i).IsFree())
            {
                i++;
                MergeUsedFragments(i);
            }
            else
            {
                FragmentBlock savedFragmentBlock = allFragmentsList.ElementAt(i);
                i++;
                //if two or more used fragments are next to each other add the sizes of the following block to the leading block and then delete them
                while (i < allFragmentsList.Count() && !allFragmentsList.ElementAt(i).IsFree())
                {
                    savedFragmentBlock.AddToSize(allFragmentsList.ElementAt(i).GetSize());
                    allFragmentsList.RemoveAt(i);
                }

                MergeUsedFragments(i);
            }
        }
Ejemplo n.º 5
0
        /**********************************************************************
         ***********************************************************************/
        public static void UpdateAllFragmentsList()
        {
            mostPromisingIndex = -1;
            foreach (FragmentBlock fb in allFragmentsList)
            {
                //Debug.Write(" |" + fb.IsFree() + " " + fb.GetSize());
            }
            FragmentBlock allocatedFb           = allFragmentsList.ElementAt(indexLastAllocated);
            int           remainingFragmentSize = allocatedFb.GetSize() - memoryRequest;

            if (remainingFragmentSize == 0)
            {
                allFragmentsList.ElementAt(indexLastAllocated).Use();
            }
            else
            {
                int           startIndex = allFragmentsList.ElementAt(indexLastAllocated).Use(memoryRequest);
                FragmentBlock newFb      = new FragmentBlock(remainingFragmentSize, true, startIndex);
                allFragmentsList.Insert(indexLastAllocated + 1, newFb);
            }
            //Debug.WriteLine("");
            //Debug.WriteLine("new fragemnts list");
            foreach (FragmentBlock fb in allFragmentsList)
            {
                //Debug.Write(" |" + fb.IsFree() + " " + fb.GetSize());
            }

            MergeUsedFragments(0);
            //Debug.WriteLine("");
            //Debug.WriteLine("merged fragemnts list");
            foreach (FragmentBlock fb in allFragmentsList)
            {
                //Debug.Write(" |" + fb.IsFree() + " " + fb.GetSize());
            }
        }
Ejemplo n.º 6
0
        private static int memoryRequest;      // current memory request made by the user

        //CONSTRUCTOR
        public AllocationStrategiesAlgorithm(String p_Strategy, List <FragmentBlock> p_AllFragmentsList)
        {
            strategy = p_Strategy;
            status   = Status.undefined; // no request made yet

            // copy List without reference to be able to alter it without affecting the original
            allFragmentsList = new List <FragmentBlock>();
            foreach (FragmentBlock p_fb in p_AllFragmentsList)
            {
                FragmentBlock fb = new FragmentBlock(p_fb.GetSize(), p_fb.IsFree(), p_fb.GetStartIndex());
                allFragmentsList.Add(fb);
            }
            freeFragmentsIndexSequenceList = new List <int>(); //empty list
            indexLastAllocated             = 0;                // start at the beginnning
            currentIndex       = -1;                           // nothing yet
            mostPromisingIndex = -1;                           //nothing yet
            memoryRequest      = -1;                           //nothing yet

            //calculate total memory size
            totalMemorySize = 0;
            foreach (FragmentBlock fb in allFragmentsList)
            {
                totalMemorySize += fb.GetSize();
            }
        }
Ejemplo n.º 7
0
        /**********************************************************************
         ***********************************************************************/
        public static void FirstFit()
        {
            // end of search not yet reached
            if (freeFragmentsIndexSequenceList.Any())
            {
                currentIndex = freeFragmentsIndexSequenceList.First();
                //Debug.WriteLine("current index: " + currentIndex);

                FragmentBlock fb = allFragmentsList.ElementAt(currentIndex);
                //if it fits perfectly or but free big enough space was found-> search was successfull
                if (memoryRequest == fb.GetSize() || memoryRequest <= fb.GetSize())
                {
                    //Debug.WriteLine("fits!");
                    indexLastAllocated = allFragmentsList.IndexOf(fb);
                    status             = Status.successfull;
                }
                // if it does not fit at all
                else
                {
                    //Debug.WriteLine("Space not big enough!");
                }
                freeFragmentsIndexSequenceList.RemoveAt(0);
            }
            // end of ring search reached
            else
            {
                //Debug.WriteLine("end of search reached!");

                // nothing found -> search was unsuccessfull
                status = Status.unsuccessfull;
            }
        }
Ejemplo n.º 8
0
        /**********************************************************************
         ***********************************************************************/
        public static void WorstFit()
        {
            //Debug.WriteLine("WORST FIT");

            // end of search not yet reached
            if (freeFragmentsIndexSequenceList.Any())
            {
                currentIndex = freeFragmentsIndexSequenceList.First();
                //Debug.WriteLine("current index: " + currentIndex);

                FragmentBlock fb = allFragmentsList.ElementAt(currentIndex);

                //if free big enough space was found
                if (memoryRequest <= fb.GetSize())
                {
                    int mostPromisingSize = 0;
                    if (mostPromisingIndex != -1)
                    {
                        mostPromisingSize = allFragmentsList.ElementAt(mostPromisingIndex).GetSize();
                    }

                    // and it's bigger than the last free space that has been found
                    if (fb.GetSize() > mostPromisingSize)
                    {
                        //Debug.WriteLine(fb.GetSize() + " bigger than " + mostPromisingSize);
                        mostPromisingIndex = allFragmentsList.IndexOf(fb);
                    }
                    // but it's not bigger
                    else
                    {
                        //Debug.WriteLine(fb.GetSize() + " unfortunately not bigger than " + allFragmentsList.ElementAt(mostPromisingIndex).GetSize());
                    }
                }
                // if it does not fit at all
                else
                {
                    //Debug.WriteLine("Space not big enough!");
                }
                freeFragmentsIndexSequenceList.RemoveAt(0);
            }
            // end of ring search reached
            else
            {
                //Debug.WriteLine("end of search reached!");

                // nothing found -> search was unsuccessfull
                if (mostPromisingIndex == -1)
                {
                    status = Status.unsuccessfull;
                }
                // fragment block found -> search was successfull
                else
                {
                    indexLastAllocated = mostPromisingIndex;
                    currentIndex       = mostPromisingIndex;
                    status             = Status.successfull;
                }
            }
        }