Esempio n. 1
0
        /**********************************************************************
         *********************************************************************/
        async void B_Start_Clicked(object sender, EventArgs e)
        {
            BuddySystem.endProcess = false;
            //check if there was a vailid input
            if (e_ProcessSize.Text != null && ValidateMemoryRequestInput())
            {
                bool bfound = BuddySystem.AllocateBlock(Int32.Parse(e_ProcessSize.Text), p_ProcessNames.SelectedItem.ToString());

                //if fitting blocksize was found
                if (bfound)
                {
                    BuddySystem.availableProcesses.Remove(p_ProcessNames.SelectedItem.ToString());
                    BuddySystem.activeProcesses.Add(p_ProcessNames.SelectedItem.ToString());
                    await Navigation.PopModalAsync(); // close Modal
                }
                else
                {
                    await DisplayAlert("Alert", "Process doesn't fit in memory", "OK");

                    await Navigation.PopModalAsync(); // close Modal
                }
            }
            else if (e_ProcessSize.Text == null)
            {
                await DisplayAlert("Alert", "Please enter a process size", "OK");
            }
            else if (!ValidateMemoryRequestInput())
            {
                await DisplayAlert("Alert", "Please enter a valid process size (only integers >= " + minimumProcessSize + ")", "OK");
            }
        }
Esempio n. 2
0
 /**********************************************************************
  *********************************************************************/
 async void B_End_Clicked(object sender, EventArgs e)
 {
     BuddySystem.endProcess = true;
     BuddySystem.activeProcesses.Remove(p_ProcessNames.SelectedItem.ToString());
     BuddySystem.availableProcesses.Add(p_ProcessNames.SelectedItem.ToString());
     BuddySystem.DeallocateBlock(p_ProcessNames.SelectedItem.ToString());
     await Navigation.PopModalAsync(); // close Modal
 }
Esempio n. 3
0
        //METHODS

        /**********************************************************************
         *********************************************************************/
        //checks if there is a block, in which the process could possibly fit in
        public static bool AllocateBlock(int processSize, String processName)
        {
            currentProcess = processName;

            //find the fitting block size
            int blockSize = BuddySystem.FindFittingBlockSize(processSize); //is 0 when process is bigger than the whole memory

            //does such a block exist? or a bigger one?
            int block = (int)absoluteMemorySize + 1; //bigger than all blocks ever available
            int index = -1;

            //find the block clostest(and still bigger) to requested blocksize
            for (int i = 0; i < buddySystem.Count; i++)
            {
                int dummy = buddySystem[i].GetBlockSize();
                if (dummy >= blockSize && dummy < block && buddySystem[i].GetFree())
                {
                    block = dummy;
                    index = i;
                }
            }
            //process bigger than memory or a blog with fitting size doesn't exist
            if (index == -1 || blockSize == 0)
            {
                return(false);
            }
            //block fits perfectly
            if (block == blockSize && buddySystem[index].GetFree())
            {
                buddySystem[index].OccupyBlock(processName, processSize);
                AddBuddySystemCell();
                b_Restart.IsEnabled = true;

                return(true);
            }

            //blocksize found but has to be split
            if (block > blockSize && buddySystem[index].GetFree())
            {
                SplitBlock(index, blockSize);
                buddySystem[index].OccupyBlock(processName, processSize);
                AddBuddySystemCell();
                b_Restart.IsEnabled = true;

                return(true);
            }
            return(false);
        }