memory-and-process-scheduler

git clone git://git.codymlewis.com/memory-and-process-scheduler.git
Log | Files | Refs | README

FrameBuffer.java (1161B)


      1 import java.util.HashMap;
      2 import java.util.Map;
      3 import java.util.ArrayList;
      4 
      5 /**
      6  * FrameBuffer - COMP2240A3
      7  * Abstract implementation of a buffer of frames for a process.
      8  *
      9  * @author Cody Lewis (c3283349)
     10  */
     11 
     12 public abstract class FrameBuffer {
     13     protected Map<Integer, Integer> loadedPages;
     14     protected int totalFrames;
     15     protected ArrayList<Integer> buffer;
     16 
     17     /**
     18      * Input constructor
     19      *
     20      * @param totalFrames Total amount of frames that can be used for the process
     21      */
     22     public FrameBuffer(int totalFrames) {
     23         loadedPages = new HashMap<>();
     24         this.totalFrames = totalFrames;
     25         buffer = new ArrayList<>(totalFrames);
     26         for (int i = 0; i < totalFrames; ++i) {
     27             buffer.add(0);
     28         }
     29     }
     30 
     31     /**
     32      * Replace a page according to the policy
     33      *
     34      * @param newPage The page the needs to be loaded
     35      */
     36     public abstract void replace(Integer newPage);
     37 
     38     /**
     39      * Use a page
     40      */
     41     public void use(int page) {}
     42 
     43     /**
     44      * Check whether a page is loaded
     45      */
     46     public boolean isLoaded(Integer pageid) {
     47         return loadedPages.containsKey(pageid);
     48     }
     49 }