• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cache program in Java  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are to construct a program that manages a 0.25 KB cache.
(That is,data upto 256 Bytes can be stored in the cache.)
Cache is organised in:

Direct Mapped, and
Fully associative.

The program takes address references in the range 0 .. 1023
and determines whether a given address reference is a hit or miss.
It also computes the Miss rate every time a miss is encountered
and at the end displays the overall Miss rate and the contents of the cache.

For displaying the cache contents, you may represent the memory
content at address A simply as M(A). You should assume that a cache block
holds 8 Bytes and, where necessary, employ the LRU scheme for block replacement.



This is my question.. any help or code would be greatly appreciated..
have made this start by constructing two classes neither compile Im not sure how to continue..



Thanks
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You say that neither compile. The best way to get answers to compile problems is to provide the error message you get when compiling the code, and highlight the code that the error message points to.
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

We can't do your work for you, but are happy to help you do it.

Write down exactly what a cache is, what it is supposed to contain, and how you are going to fill it. How are you going to get 256 bits of data (or are those 256 "words" into 1025 spaces)? How are you going to get things out again?
 
john mater
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have test data.. so that my program compares the difference between mapped and associative.

In my memory Array i get the error "int cannot be dereferenced" then i'm not sure what to do after this.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You have an integer (int type) called randnum. You pass an integer (int type) into the method (and call it Random). The integer is a primitive, not an Object. So when you try to call randnum.nextInt(1023); you are trying to call a method on randnum. But randnum is not an Object so you can't call a method on it.

So the question is, what type of Object do you think has the method called nextInt(int) that you want to call? If you look at the API's Index (for N) you might find the Method you want to call, follow links back to the Class you want to use to call the method.
 
john mater
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sorted that out.. Both Classes compile now.. which I guess is a start. My Memory Class at the moment is basically a random number generator. My Cache class is still very much work in progress. Am I right in thinking I need my Cache class to act as a search through the numbers generated in Memory to see whether the numbers given to me in my test data appear in Memory? If this is the case I can do this for fully associative Cache but Direct Mapped is slightly confusing as each number is pre assigned to an array slot in the Cache.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!