Question: EDIT BELOW IN LEAST USED REPLACEMENT POLICY IN LINUX. edit: If you type make rand in bash, a simulator will be created that uses a
EDIT BELOW IN LEAST USED REPLACEMENT POLICY IN LINUX.
edit:
If you type make rand in bash, a simulator will be created that uses a cache with a random replacement policy. The code that implements a cache with a random replacement policy is in random_cache.h and random_cache.c.
Your job is to edit files lru_cache.h and lru_cache.c such that they implement a least-recently-used replacement policy. Do not edit any other files!
I will test your code by running the simulator, and also by running unit tests. When I run the simulator that uses the random replacement policy, I get:
hits: 73548; misses: 26452
When I run the simulator using my cache implementation with a least-recently-used replacement policy, I get (and you should get):
hits: 78399; misses: 21601
#HEADER FILE
typedef struct cache { // // your code here // } CACHE; CACHE *cache_new(int size); float cache_lookup(CACHE *cache, int i); void cache_insert(CACHE *cache, int i, float x); void cache_clear(CACHE *cache, int i);
#CFILE
#include #include "lru_cache.h"
// // Your implementations of cache_new, cache_lookup, cache_insert, // and cache_clear go in this file. You must use a least-recently-used // cache replacement policy. //
// return a new cache object CACHE *cache_new(int size) { // your code here }
// return data element i if it is cached; else return -1 float cache_lookup(CACHE *cache, int i) { // your code here }
// record in the cache that the ith data element has value x // LRU replacement policy is used void cache_insert(CACHE *cache, int i, float x) { // your code here }
// clear the ith element of the cache void cache_clear(CACHE *cache, int i) { // your code here }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
