* after you destroy it to prevent a double free. * Function that destroys a created cache. * By default insert blocks where valid = 0 */Ĭache-> blocks = (Block) malloc( sizeof( struct Block_ ) ) * write_policy 0 = write through, 1 = write backĬache createCache( int cache_size, int block_size, int write_policy)Ĭache-> numLines = ( int)(CACHE_SIZE / BLOCK_SIZE) Ĭache-> blocks = (Block*) malloc( sizeof(Block) * cache-> numLines ) Printf( "CACHE HITS: %i \nCACHE MISSES: %i \nMEMORY READS: %i \nMEMORY WRITES: %i \n ", cache-> hits, cache-> misses, cache-> reads, cache-> writes) If(DEBUG) printf( "Num Lines: %i \n ", counter)
If(DEBUG) printf( " %i: %c %s \n ", counter, mode, address) While( fgets(buffer, LINELENGTH, file) != NULL ) \n ") Ĭache = createCache(CACHE_SIZE, BLOCK_SIZE, write_policy) sim \n ") įprintf(stderr, "Error: Could not open file. If(DEBUG) printf( "Write Policy: Write Back \n ") įprintf(stderr, "Invalid Write Policy. If(DEBUG) printf( "Write Policy: Write Through \n ") \n\twb - simulate a write back cache \n\n is the name of a file that contains a memory access trace. Tag = ( char *) malloc( sizeof( char) * (TAG + 1) ) įor(i = 0 i \n\n is one of: \n\twt - simulate a write through cache. Printf( "Formatted: %s \n ", bformatted) * calculates the corresponding tag, index, and offset.Ĭhar *bstring, *bformatted, *tag, * index, *offset * binary, and formatted binary equivilants. * the format of "0x00000000" and spits out the decimal, * Helper function that takes in a hexidecimal address in * Converts hexidecimal memory locations to unsigned integers. * block_size How big each block of data should be * cache_size Total size of the cache in bytes * misses # of cache accesses that missed valid data * hits # of cache accesses that hit valid data * the write policy, sizes, and an array of blocks. * Cache object that holds all the data about cache access as well as * the bit is dirty or not (0 = clean, 1 = dirty).
* 1 = valid), the tag being held, and another integer that states if * Holds an integer that states the validity of the bit (0 = invalid, * is the name of a file that contains a memory access trace. * and either a write through or write back policy. * This is a program that simulates a cache using a trace file