-
November 2nd, 2014, 12:52 PM
#1
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();
-
November 3rd, 2014, 11:10 AM
#2
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?
Norm
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|