Out of practice and lost

Discussion in 'Homework Help' started by silvrstring, Dec 15, 2008.

  1. silvrstring

    Thread Starter Active Member

    Mar 27, 2008
    159
    0
    Hello, everyone.

    I am trying to make a simple simulation of memory usage using a round-robin, first-fit approach. I am using a struct array to predetermine the attributes of the processes that will attempt to use the simulated "memory" array. The attributes are size, arrival time, and duration time. I know I'll have to use a queue as the "memory" array is filled and new "processes" are waiting their turn.

    The big problem I am running into right now is once a "process" has found its "fit," how do I start the countdown until termination for that "process," and at the same time let the new loop for the next "process" start. The way I have it set up, it will not start looking for a space for the next one until the duration time for the first process is up. I also want it to step in when that time is up and let the user know that it has exited.

    Any ideas? Thanks if you can help.
     
  2. veritas

    Active Member

    Feb 7, 2008
    167
    0
    I've only looked at your code for a few minutes, so I may be missing something, but I noticed a few things that cause the program to behave differently from how I understand that it should:
    1) you only loop through memory once, which means that if memory is freed after a process ends, that space will not be reused.
    2) each process is only addressed once: you never address a process other than newProcess, which means that it is not possible for another process to "start" while one is still "running".
    3) newProcess.startDuration() seems to loop? which means it appears to return "time" every time it is called.

    It seems to me that you need to loop through time while all of your processes are not finished, instead of looping through memory as your outer-most loop.
     
  3. silvrstring

    Thread Starter Active Member

    Mar 27, 2008
    159
    0
    Thanks Veritas, I'm looking over it right now.

    for 1), I'm fixing the memory loop now.
    for 2), I'm not sure what you mean.
    for 3), yes, it only counts down the time the process is in memory. I don't really need it to return time; I can just use it as a counter.

    I'm gonna try something like you suggest with a time loop.

    How can I address other processes? Do you mean I should use other structs such as nextProcess[]...oldProcess[]...etc.,?
     
  4. veritas

    Active Member

    Feb 7, 2008
    167
    0
    I mean that if you're going to have more than one process "active" at a time, then you need to have some sort of loop that checks all of the processes and updates them. Something like
    Code ( (Unknown Language)):
    1.  
    2. loop over time
    3. {
    4.   for each process in newProcesses
    5.   {
    6.      check if needs to be started
    7.      if active
    8.      {
    9.         check if done
    10.      }
    11.   }
    12. }
    13.  
     
  5. silvrstring

    Thread Starter Active Member

    Mar 27, 2008
    159
    0
    Danke, your truthiness!

    I think I can work with that.

    Thanks again
     
Loading...