![]() |
|
#1
|
||||
|
||||
C program for Cache Memory Simulation based on UNIX CHi everyone
If Anyone can help me in this program development I will be really greatful. I really appreciate your help in advance. program should emulate a cache memory server. Input to program is a file (cache.in) with the addresses of disk requests. The data is of the form... 19 8 17 16 3 3 20 8 4 - - - open the input file initialize the tables loop read in 1 page number if this page is in the cache then bump the number of references (value) else move nubers 17,18,19 down 1, and insert the page # into cache[17] sort on the value (high to low) print the report every 20 requests, go through and decrement the number of references (if the reference is > 0) print the entire cache table until end of file ================================================== ======================== The first part of the output should look, pretty much, like the following: page 19 slot disk value number addr 1 19 1 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 8 slot disk value number addr 1 19 1 2 8 1 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 17 slot disk value number addr 1 19 1 2 8 1 3 17 1 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 16 slot disk value number addr 1 19 1 2 8 1 3 17 1 4 16 1 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 3 slot disk value number addr 1 19 1 2 8 1 3 17 1 4 16 1 5 3 1 6 0 0 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 3 slot disk value number addr 1 3 2 2 19 1 3 8 1 4 17 1 5 16 1 6 0 0 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 20 slot disk value number addr 1 3 2 2 19 1 3 8 1 4 17 1 5 16 1 6 20 1 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 8 slot disk value number addr 1 3 2 2 8 2 3 19 1 4 17 1 5 16 1 6 20 1 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 4 slot disk value number addr 1 3 2 2 8 2 3 19 1 4 17 1 5 16 1 6 20 1 7 4 1 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 page 10 slot disk value number addr 1 3 2 2 8 2 3 19 1 4 17 1 5 16 1 6 20 1 7 4 1 8 10 1 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 Thankyou |
|
#2
|
|||
|
|||
Re: C program for Cache Memory Simulation based on UNIX CThe regulars here will probably complain in more detail, but if you don't post at least an attempt at coding this, you'll get little or no help.
|
|
#3
|
|||
|
|||
Re: C program for Cache Memory Simulation based on UNIX CQuote:
Namely, just posting a homework assignment and saying, "I don't know how to do it," isn't likely to get helpful responses. However I recognize that knowing how to ask a question that might get good results is also a learning process, just as trying to figure out how to help someone is a learning process. I am still learning. To the original Poster: First item: understand the problem. Do you know exactly what the program is supposed to do? I find the description pretty good, but if people aren't familiar with some of the concepts here, it might be difficult to follow the example. Why does that particular sequence of inputs result in the conditions shown? Assignments like this are usually made in some context (although it might seem that it just came out of the blue). Maybe some of the concepts were covered in an earlier class --- or maybe not. Maybe that class was waaaay back last semester. Maybe you haven't even had this stuff yet and part of the programming assignment is to figure out what the heck it's talking about and then write the program. Whatever... Second item: Once the concept is understood, you might think of how a program could accomplish the assigned task. 1. You will have a cache (probably an array in C). 2. The cache will have 20 entries, according to the example (so it's an array of 20 "somethings"). 3. Each entry in the cache has two things associated with it: a disk address and a value. How do I know this: The output in the example has three columns: Code:
So, the first column represents an array index, the second is an integer representing the address of a request, and the third column is an integer that represents the number of requests for that address. All of my above conclusions are based somewhat on my familiarity with some concepts that may not be obvious to some people (and, of course, I could be wrong, but that's my take on the problem so far). Now we can visualize an array of structs. Each struct has two int members: an address and a count value. Initially the array is populated with structs that have zero values for their members. I hate to get ahead of myself, but the first thing we will do in the program is to define a struct of this type and then declare an array of 20 such things. Also, since we will need to print out the contents of the cache (the array) at various points in the program, consider that we will more than likely want a function to print out the results in some nice, neat manner. Details of the implementation don't have to be worked out just yet, but it's nice to realize such things early in the game. Now, what is the program going to do with this data structure that we have postulated? It will repeatedly read new requests from a file. So, the program has to be able to open a file and read integer values (the addresses of the requests). That also means that we will need a file that the program can read. Just make a file with a text editor that has input values shown in the example. Now stop. Do everything that I have mentioned so far. Make a loop that reads all of the requests from the input file. For now, just print out each value as it is read. Don't worry about putting new requests into the cache (the array) just yet. Make absolutely sure that your program can read the correct value for each and every input item, and make sure that it stops when all items have been read. If you have any problems understanding or implementing these things, then ask again. Be specific. Show what you have tried and explain what didn't work the way that you expected. Regards, Dave "No one was born knowing this stuff, you know." ---daveks7x |
Recent GIDBlog
Welcome to Baghdad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pipeline freeze simulation | darklightred | C++ Forum | 6 | 27-Jul-2006 19:37 |
| How to read particular memory location ? | realnapster | C Programming Language | 10 | 10-May-2006 09:11 |
| Memory de-allocation during debugging | gaoanyu | C Programming Language | 12 | 19-Dec-2005 04:50 |
| Pointer Usage in C++: Beginner to Advanced | varunhome | C++ Forum | 0 | 19-Aug-2005 09:25 |
| [Tutorial] Pointers in C (Part I) | Stack Overflow | C Programming Language | 1 | 08-Apr-2005 18:35 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The