mirror of
https://github.com/bspeice/itcs3146-project
synced 2024-12-22 06:38:23 -05:00
Debugging code
This commit is contained in:
parent
51aad5ee74
commit
a468512e16
@ -22,10 +22,12 @@ class FirstFit implements baseAlgorithm
|
||||
noJobs=0,
|
||||
s1=0,
|
||||
compMemTest=0,
|
||||
jobLoaded=0,
|
||||
tableEntries=1;
|
||||
private int[] tempVal = new int[6];
|
||||
private int[][] memTable = new int[memSize+2][6];
|
||||
private int[] memory = new int[memSize];
|
||||
private Job[] jobArray = new Job[memoryManagement.JOBAMOUNT+10];
|
||||
|
||||
//this is a no argument constructor
|
||||
public FirstFit()
|
||||
@ -63,6 +65,15 @@ class FirstFit implements baseAlgorithm
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//this will loop until job is loaded into memory
|
||||
do
|
||||
{
|
||||
|
||||
//this section looks for a place to put the new job
|
||||
do
|
||||
{
|
||||
@ -79,6 +90,7 @@ class FirstFit implements baseAlgorithm
|
||||
memTable[s1][5] = 1;
|
||||
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
|
||||
fillMemory(jobId, jobSize, memTable[s1][2]);
|
||||
jobArray[jobId - 1] = newJob;
|
||||
newJob.start();
|
||||
memTable[s1+1][0] = 0;
|
||||
memTable[s1+1][1] = 0;
|
||||
@ -87,7 +99,8 @@ class FirstFit implements baseAlgorithm
|
||||
memTable[s1+1][4] = memSize-memTable[s1+1][2];
|
||||
memTable[s1+1][5] = -1;
|
||||
tableEntries++;
|
||||
System.out.println(toString());
|
||||
jobLoaded=1;
|
||||
System.out.println("add job "+jobId+toString());
|
||||
s1=memSize*2;
|
||||
}
|
||||
//runs after the first job and if the only available slot is at the end of memory
|
||||
@ -101,6 +114,7 @@ class FirstFit implements baseAlgorithm
|
||||
memTable[s1][5] = 1;
|
||||
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
|
||||
fillMemory(jobId, jobSize, memTable[s1][2]);
|
||||
jobArray[jobId - 1] = newJob;
|
||||
newJob.start();
|
||||
memTable[s1+1][0] = 0;
|
||||
memTable[s1+1][1] = 0;
|
||||
@ -109,7 +123,8 @@ class FirstFit implements baseAlgorithm
|
||||
memTable[s1+1][4] = memSize-memTable[s1+1][2];
|
||||
memTable[s1+1][5] = -1;
|
||||
tableEntries++;
|
||||
System.out.println(toString());
|
||||
jobLoaded=1;
|
||||
System.out.println("add job "+jobId+toString());
|
||||
s1=memSize*2;
|
||||
}
|
||||
}
|
||||
@ -121,8 +136,10 @@ class FirstFit implements baseAlgorithm
|
||||
memTable[s1][5] = 1;
|
||||
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
|
||||
fillMemory(jobId, jobSize, memTable[s1][2]);
|
||||
jobArray[jobId - 1] = newJob;
|
||||
newJob.start();
|
||||
System.out.println(toString());
|
||||
jobLoaded=1;
|
||||
System.out.println("add job "+jobId+toString());
|
||||
s1=memSize*2;
|
||||
}
|
||||
else
|
||||
@ -130,15 +147,20 @@ class FirstFit implements baseAlgorithm
|
||||
s1++;
|
||||
}
|
||||
}while(s1<tableEntries);
|
||||
|
||||
|
||||
//if job will not fit this section will compress memory and try placing the job again
|
||||
//if job will not fit this section will compress memory
|
||||
if(s1==tableEntries)
|
||||
{
|
||||
noJobs=noJobs-1;
|
||||
compMem();
|
||||
allocate(ID, size, jobTime);
|
||||
}
|
||||
|
||||
}while(jobLoaded==0);
|
||||
s1=0;
|
||||
jobLoaded=0;
|
||||
|
||||
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.out.println("Could not allocate job with ID " + jobId);
|
||||
@ -147,57 +169,34 @@ class FirstFit implements baseAlgorithm
|
||||
|
||||
|
||||
|
||||
//this method is used if you want to deallocate a job by jobId
|
||||
public void removeJob(int ID)
|
||||
{
|
||||
jobId = ID;
|
||||
s1=0;
|
||||
do
|
||||
{
|
||||
if(memTable[s1][0] == jobId)
|
||||
{
|
||||
jobSize = memTable[s1][1];
|
||||
startLoc = memTable[s1][2];
|
||||
s1=memSize*2;
|
||||
}
|
||||
else
|
||||
{
|
||||
s1++;
|
||||
}
|
||||
|
||||
}while (s1<tableEntries);
|
||||
deallocate(jobSize, startLoc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//this method removes a job it does not check to see if the job exisits
|
||||
public void deallocate(int jobSize, int beginningLocation)
|
||||
//public void removeJob(int ID)
|
||||
public void deallocate(int jSize, int beginningLocation)
|
||||
{
|
||||
jobId = 0;
|
||||
jobSize = jobSize;
|
||||
jobSize = jSize;
|
||||
startLoc = beginningLocation;
|
||||
s1=0;
|
||||
do
|
||||
{
|
||||
if(memTable[s1][2] == startLoc)
|
||||
{
|
||||
|
||||
System.out.println(startLoc+" removed job "+memTable[s1][0]);
|
||||
memTable[s1][0] = 0;
|
||||
memTable[s1][1] = 0;
|
||||
memTable[s1][5] = 0;
|
||||
s1=memSize*2;
|
||||
jobId=-1;
|
||||
System.out.println(memTable[s1][0]+" "+memTable[s1][1]+" "+memTable[s1][5]);
|
||||
System.out.println(toString());
|
||||
noJobs--;
|
||||
System.out.println("removed job "+memTable[s1][0]);
|
||||
s1=memSize*2;
|
||||
}
|
||||
else
|
||||
{
|
||||
s1++;
|
||||
}
|
||||
|
||||
}while (s1<tableEntries);
|
||||
|
||||
}
|
||||
|
||||
//this method compacts the memory
|
||||
|
Loading…
Reference in New Issue
Block a user