Forums Register Login

Cache program in Java

+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send


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.
+Pie Number of slices to send: Send
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.
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4591 times.
Similar Threads
problem
arrays help
methods help
memory to cache problem
Can Somebody please help me with my code?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:51:04.