Support smaller number of frames than pages
Hi,
I've written a FIFO (First-In First-Out) Algorithm function, and I am trying to provide support for smaller number of frames than pages.
Code:
private void pageFaultFIFO(int pageNumber){
pageFaults++;
for(int i = 0; i<pageTable.length; i++){
if(pageTable[i] == freePos)
pageTable[i] = -1;
}
try {
pageFile.seek(pageNumber*PageSize);
for(int b=0;b<PageSize;b++)
RAM[freePos*PageSize+b]=pageFile.readByte();
} catch (IOException ex) {
Logger.getLogger(MemoryManager.class.getName()).log(Level.SEVERE, null, ex);
}
pageTable[pageNumber] = freePos;
if(pageTable.length == pageNumber){
freePos = 0;
}
else{
freePos++;
}
}
I made it work, when I pass 255, 255, 255, all equal sizes. But if the last number of frames is e.g. 128, I get ArrayIndexOutOfBoundsException: 32768. I am not sure, how can I modify a small change to support all types of sizes dynamically?
The problem in particularly occurs at RAM[freePos*PageSize+b]=pageFile.readByte();
Re: Support smaller number of frames than pages
Can you explain the code's logic?
On What statement does the exception happen? What are the values of the variables used to compute the index?