6 Replies - 7522 Views - Last Post: 28 October 2012 - 05:05 AM Rate Topic: -----

#1 asymptotes14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 27-February 11

First Fit OS simulation

Posted 19 October 2012 - 07:08 AM

im trying to simulate the first fit algorithm ive learned in Operating systems
i have made 3 arraylists that contains job name, job size, and job time,

i have a listview box that is like this
|Memory block| Memory Size | Time | Job on process|
Mb1 | 2500
and so on

ive made this code
  for (int i = 0; i <= listViewJobOnProcess.Items.Count - 1; i++)
                {
                    
                        if (Int32.Parse(size[0].ToString()) <= Int32.Parse(listViewJobOnProcess.Items[i].SubItems[1].Text))
                        {
                            listViewJobOnProcess.Items[i].SubItems.Add(time[0].ToString());
                            listViewJobOnProcess.Items[i].SubItems.Add(name[0].ToString());
                        }
                }


but doesnt really work how i wanted it,
it loops through the listviewbox and checks if the job size of the job is fitted on the partition,
but my problem is, the job lists to every partition that returns a true value, this is where im having trouble

any help on this?

Is This A Good Question/Topic? 0
  • +

Replies To: First Fit OS simulation

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,903
  • Joined: 08-June 10

Re: First Fit OS simulation

Posted 19 October 2012 - 07:38 AM

Moved to the C# forum. The advanced discussion area is not for help questions.
Was This Post Helpful? 0
  • +
  • -

#3 dhazard  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 67
  • Joined: 06-September 06

Re: First Fit OS simulation

Posted 19 October 2012 - 08:36 AM

Can you Post a little more code and walk me through what you are trying to do im not fully understanding right now.

This post has been edited by dhazard: 19 October 2012 - 08:36 AM

Was This Post Helpful? 0
  • +
  • -

#4 asymptotes14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 27-February 11

Re: First Fit OS simulation

Posted 21 October 2012 - 04:39 AM

View Postdhazard, on 19 October 2012 - 08:36 AM, said:

Can you Post a little more code and walk me through what you are trying to do im not fully understanding right now.

my form looks something like this in the attached picture
i'm trying to simulate the first fit algorithm,
so all the values in the text boxes i've places inside an arraylist time and size,

View Postdhazard, on 19 October 2012 - 08:36 AM, said:

Can you Post a little more code and walk me through what you are trying to do im not fully understanding right now.

my form looks something like this in the attached picture
i'm trying to simulate the first fit algorithm,
so all the values in the text boxes i've places inside an arraylist time and size,

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 marty617  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 33
  • Joined: 14-October 12

Re: First Fit OS simulation

Posted 27 October 2012 - 08:11 AM

It's hard to tell what you have going on around on the outside of that loop, but why are you always comparing to size[0]? This looks like it scans the buckets for a place to put the item but always looks at the first item and doesn't seem to do anything to stop looking for buckets onces that item has a bucket it will fit into.
Was This Post Helpful? 0
  • +
  • -

#6 asymptotes14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 27-February 11

Re: First Fit OS simulation

Posted 28 October 2012 - 03:58 AM

View Postmarty617, on 27 October 2012 - 08:11 AM, said:

It's hard to tell what you have going on around on the outside of that loop, but why are you always comparing to size[0]? This looks like it scans the buckets for a place to put the item but always looks at the first item and doesn't seem to do anything to stop looking for buckets onces that item has a bucket it will fit into.


this is what i have so far after reading about arraylists,
foreach (string x in size)
              {                                                
                  foreach (string y in memSize)
                  {
                      if (Int32.Parse(x) <= Int32.Parse(y))
                      {
                          listViewJobOnPro.Items.Add(x.ToString());                           
                          memSize.Remove(y);                         
                      }
                      else
                      {
                          listViewJobQueue.Items.Add(x.ToString());                     
                      }
                      break;
                  }                 
              }          



i still have items left inside my size arraylist,im having trouble sending them to the listviewbox
any suggestion on how i can fix this
Was This Post Helpful? 0
  • +
  • -

#7 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 182
  • View blog
  • Posts: 783
  • Joined: 27-October 11

Re: First Fit OS simulation

Posted 28 October 2012 - 05:05 AM

First off, arrayLists are obsolete, if you want generics, you should use a List<>.

Another thing, if x and y are strings, you don't need to call the .ToString() method when adding them to the items of the listView.

And yet another thing, if those variables represent numbers, why not use the appropriate type? Like int. That way there won't be any unnecessary parsing to integer.

And the reason why you have some variables in the arrayList, is because you can't change the arrayList you're looping through directly, you have to use a for loop if you want to do that.

This post has been edited by RexGrammer: 28 October 2012 - 05:07 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1