dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Support smaller number of frames than pages

  1. #1
    Join Date
    Nov 2014
    Posts
    1

    Question 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();

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,856

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)