src/HardDrive.cpp
int HardDrive::findNextFreeChunk(int index) const {
    
    //Make sure this was called legally
    Assert(0<=index&&index<size(), "Index out of bounds");
    
    //Set true if a block of used memory has been found
    int i, foundUsed = false;
    
    //Repeat for each index in memory
    for(i=index+1; i < size(); i++) {
        
        //If a used block of memory has yet to be found
        if (!foundUsed) {
            if (memory[i]) foundUsed = true;
        }
        
        //If a new chunk was found, return it's index
        else if (!memory[i]) return i;
    }
    
    //If no memory is free
    return -1;
}
//Returns the location of the next free chunk
//of memory after index, assumes index is free
//Returns -1 if there is no free memory in the system
Returns the location of the next free chunk
of memory after index, assumes index is free
Returns -1 if there is no free memory in the system
Returns the location of the next free chunk of memory after index assumes index is free Returns - 1 if there is no free memory in the system
int HardDrive::findNextFreeChunk(int index) const {
    Assert(0<=index&&index<size(), "Index out of bounds");
    int i, foundUsed = false;
    for(i=index+1; i < size(); i++) {
        if (!foundUsed) {
            if (memory[i]) foundUsed = true;
        }
        else if (!memory[i]) return i;
    }
    return -1;
}
int HardDrive :: findNextFreeChunk ( int index ) const { Assert ( 0 <= index && index < size ( ) , " " ) ; int i , foundUsed = false ; for ( i = index + 1 ; i < size ( ) ; i ++ ) { if ( ! foundUsed ) { if ( memory [ i ] ) foundUsed = true ; } else if ( ! memory [ i ] ) return i ; } return -1 ; }
Returns the location of the next free chunk
of memory after index, assumes index is free
Returns -1 if there is no free memory in the system
Returns the location of the next free chunk of memory after index assumes index is free Returns - 1 if there is no free memory in the system
//Make sure this was called legally //Set true if a block of used memory has been found //Repeat for each index in memory //If a used block of memory has yet to be found //If a new chunk was found, return it's index //If no memory is free