Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a java class which demonstrates principle of a direct mapped computer

ID: 3570461 • Letter: I

Question

Implement a java class which demonstrates principle of a direct mapped computer cache. Your cache class can model a cache with a limited size integer array and a tag array. Your main program can generate a large array representing memory. During the program (e.g. loop printing values) request values from the cache with reference to large array indexes. Your cache must check whether it stores the given indexed (addressed) value in the class, if so, it returns the value. If not it must return some value indicating the value does not present. However, at the same time your cache class must bring from the main memory a new block which will include the given index.

Explanation / Answer

import java.util.ArrayList;   

public class Temp {   

public static void main(String args[]){   
int n = Integer.parseInt(args[0]);   
int k=100000;   
  
ArrayList<String> list = new ArrayList<String>(n);   
char[] array = new char[3];   

for(int i=0;i<n;i++){   

array[0] = 'a';   
array[1] = 'b';   
array[2] = 'c';   
list.add(new String(array));   

if(i%k == 0){   
long m1 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();   
m1 /= (1024*1024);   
System.out.println("memory used when "+i+" key inserted ="+m1+" MBytes.");   
}   
}   
  

}   
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote