PagedArray.cpp
/**
 * Replacement algorithm, decides which page to free
 * @return The page array of the newly allocated page in memory
 */
Replacement algorithm, decides which page to free
@return The page array of the newly allocated page in memory
Replacement algorithm decides which page to free @return The page array of the newly allocated page in memory
int PagedArray::freePage() {
    int toReplace = 0;
    int maxValue = -1;
    int i;
    for (i = 0; i < NUMPAGES; i++) {
        if (loadedPages[i] == -1) {
            toReplace = i;
            break;
        }
        if (loadedPages[i] == lastAccessed)
            continue;
        if (accessNumbers[i] >= maxValue) {
            toReplace = i;
            maxValue = accessNumbers[i];
        }
    }
    FileHandler::writeNumbers(file, pageContainer[toReplace], loadedPages[toReplace]);
    delete (pageContainer[toReplace]);
    loadedPages[toReplace] = -1;
    return toReplace;
}
int PagedArray :: freePage ( ) { int toReplace = 0 ; int maxValue = -1 ; int i ; for ( i = 0 ; i < NUMPAGES ; i ++ ) { if ( loadedPages [ i ] == -1 ) { toReplace = i ; break ; } if ( loadedPages [ i ] == lastAccessed ) continue ; if ( accessNumbers [ i ] >= maxValue ) { toReplace = i ; maxValue = accessNumbers [ i ] ; } } FileHandler :: writeNumbers ( file , pageContainer [ toReplace ] , loadedPages [ toReplace ] ) ; delete ( pageContainer [ toReplace ] ) ; loadedPages [ toReplace ] = -1 ; return toReplace ; }
Replacement algorithm, decides which page to free
 @return The page array of the newly allocated page in memory
Replacement algorithm decides which page to free @return The page array of the newly allocated page in memory
//printf("Last accessed is: %i\n", lastAccessed); //printf("LoadedPages: %d %d %d %d %d %d\n", loadedPages[0], loadedPages[1], loadedPages[2], loadedPages[3], loadedPages[4], loadedPages[5]); //printf("AccessedPages: %d %d %d %d %d %d\n", accessNumbers[0], accessNumbers[1], accessNumbers[2], accessNumbers[3], accessNumbers[4], accessNumbers[5]); //printf ("Will free slot: %d\n", toReplace);