// Albert Coba and Shawn Nematbakhsh // cs161 as3 - cache similator // // These are the function definitions for the cache block class. #include "block.h" // this is the constructor. It takes the size of the cache and the // replacement policy(0=LRU,1=FIFO) and initializes the values. block::block(int s,bool replacement) { // set size and replacement method size=s; replacement_method=replacement; // array for valid bits valid=new bool[size]; // array for tags tag=new int[size]; // array to keep track of LRU/FIFO lru=new int[size]; // set arrays to zero initially reset(); } // empty constructor, init has to be called if this is used. block::block() { } // this is the destructor, it frees up the memory dynamically allocated // in the arrays. block::~block() { // quit if arrays haven't been allocated if(!valid) return; // otherwise delete them delete valid; delete tag; delete lru; } // this function is the same as the first constructor. It exists so that // arrays of blocks can be declared with different size/replacements. void block::init(int s,bool replacement) { // set size/replacement size=s; replacement_method=replacement; // set/initialize arrays valid=new bool[size]; tag=new int[size]; lru=new int[size]; reset(); } // this function sets all arrays used in the class to zero and sets // the counts to zero void block::reset() { // set all data in the arrays to zero for(int i=0;i passed value if(lru[j+base] > value) --lru[j+base]; }