Posted: 10/24/2001 10:30:45 PM EDT
|
I've got an assignment due in my Operating Systems class due in two days. The time to do it is plentiful, but the knowledge in the Jew's brain is not. I've been working with so much Java lately, that there's no way I can do this assignment in C++ ...not to mention they never taught us the language at all, so I just taught myself the "basics". Here's the deal, I'll let the requirement guidelines in the "Problem Statement" section speak for itself: [url]http://www.eng.auburn.edu/department/csse/classes/comp3500/index.html[/url] I understand the concept, and I figure I'll probably want to use FIFO, LRU, and Second-Chance as my 3 algorithms. I'm not asking anybody to WRITE the darn thing for me, perish the thought. But if you have any resources which I could use, i.e. out of a book, a URL, an old algorithm library laying around, etc....PLEASE direct me. I need help desperately on this assignment, especially since I'm totally stumped how I'm going to approach the assignment. Chances are the only thing I'll even know how to write is the simple driver class (er, "main function", geez I can't even get the names right) [:\] I'm in your debt if you can help me out. |
|
Looks like you haven't been doing your homework. . . . [:D] Is this the producer-consumer problem in http://www.eng.auburn.edu/department/csse/classes/comp3500/projects/Project%201A.pdf or is it one of the other assignments?? There are seven "homework" and two "project" things listed. (I didn't look at the second project since it's apparently a MS-Word file. . . .) |
|
Quoted: The jews grades so far, we better help out here: AR15jew.....85.....70.....0.....no quiz Ohhh wait nevermind, this place isn't accredited. Quizzes are just extra-credit...but yes, I have a lot of 0 homework grades. I can never get them turned in on time, I usually opt to turn in my Scheme assignments instead. Nevertheless, this project will bring me down if I can't figure out how to do it. Time never was the issue, ignorance is - I still know no way in hell of approaching this, so I'll probably end up taking a failure on it. |
|
Quoted: BTW, what is an LRU? Don't think I heard of that term before. Least Recently Used As for part two... well I can't help you on the C++ end (they teach us ADA here of all things). I have a specification (i.e. procedure names and parameters, and some comments about what they should do) for almost this exact problem. The spec is written in Ada though. Could give you some ideas maybe. Probably talking either an array of records (easier) or linked list (more complex). Each time an entry gets called, you check the "cache" (the array of records). If it's in there, you update its use and move on. If not, you page in the new appropriate val, dumping the appropriate old val. Well, if I'm making any sense, or you want a look at the spec, or want to otherwise contact me... I'm editing my profile to allow my email to be seen. Viper Out |
|
Quoted: What are you having trouble with? This project doens't seem TOO hard, it just takes a little time. I've got my C++ books laying around. Just let me know what you need and I might be able to help. BTW, what is an LRU? Don't think I heard of that term before. LRU - Least Recently Used This really looks like a pretty easy assignment. Since you could use C or C++, I'd opt for C. More straightforward than doing this in C++, and quicker. All you've got to do is allocate an array of either 4 or 8 to hold int's. Using the appropriate algorithm, the "page" is either in "memory" (the array), or it isn't. |
|
Quoted: All you've got to do is allocate an array of either 4 or 8 to hold int's. Wouldn't it be an array of records, rather than ints? You would want to keep track of the time last used for LRU. If you needed to keep track of any other info (how many times page has been accessed), you could just slam it into the record structure as well. Viper Out |
|
Quoted: If you want, I can send you an old project I did that held an array or records. It might give you an idea. Maybe you can switch things around. Sure, that'd give me something to work with as far as my paged memory. I'm still trying to develop just ONE working algorithm for it. Plus, I gotta learn how to do "Math.Random" numbers, or C++'s functional equivalent. Too bad C++ doesn't have a website like www.java.sun.com ...makes things SO much tougher. |
|
Plus, I gotta learn how to do "Math.Random" numbers, or C++'s functional equivalent. Too bad C++ doesn't have a website like www.java.sun.com ...makes things SO much tougher. The generic random number generator in C is rand(). I think the library is stdlib.h. It returns a number from 0 to RAND_MAX. |
|
For the FIFO you can use nn array of ints, but for the LRU you need an array or linked list of structures. If you use the STL in C++, the list management becomes a no brainer. For instance, for the FIFO, you could do this: #include #include const int NFRAMES = 4; static void fifo_add( int item, int& rfaults ); static std::list int main(int argc, char* argv[]) { int i, nfaults; int data[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 7, 4, 6, 5, 4, 6, -1}; nfaults = 0; fifo_list.clear(); for (i=0; data[i] != -1; i++) fifo_add(data[i], nfaults); printf("\n%d page faults.\n", nfaults); getchar(); return 0; } static void fifo_add( int item, int& rfaults ) { std::list it = find(fifo_list.begin(), fifo_list.end(), item); if (it == fifo_list.end()) { // not found if (fifo_list.size() == NFRAMES) fifo_list.erase(fifo_list.begin()); fifo_list.push_back(item); printf("%d\n", item); rfaults++; } } BTW, if you don't see the subscript operators, it's because they were removed when I posted this message. Don't ask me why. |
|
Quoted: Quoted: If you want, I can send you an old project I did that held an array or records. It might give you an idea. Maybe you can switch things around. Sure, that'd give me something to work with as far as my paged memory. I'm still trying to develop just ONE working algorithm for it. Plus, I gotta learn how to do "Math.Random" numbers, or C++'s functional equivalent. Too bad C++ doesn't have a website like www.java.sun.com ...makes things SO much tougher. To generate random numbers within a range you specify, use random(). |
|
Mattja, Nice use of an array! I can't get over the diversity that make up the members of this forum. Just a couple of days ago, there was an audiophile discussion on high end loud speakers and now C++??? Glad to see this forum is not just a typical firearms discussion site. |
|
There's nothing hard about doing this project in C, you just have to think about the problem--get a hold of an operating systems text that describes the algorithms you are going to use. Most have example code in them. You should be able to find sample C code for the algorithms, so I wouldn't beat my brains out trying to re-invent them as long as you understand what they do. You may have to alter them for use with your simulation. I say "C" and not "C++" because you really aren't doing any object-oriented programming for this assignment, correct? It's too bad they teach students Java from the get-go these days. It confuses the hell out of everything for those just starting out--too many libraries and canned routines for everything under the sun. No good for teaching fundamentals. My advice is for you to learn the concepts behind paging and memory management and the rest will come easily--just stick to basic I/O like cin and cout (or fprintf and printf) and write routines that work on arrays. Many moons ago I had to write a whole Pascal intepreter in C. It was a struggle and very frustrating, but I look back on those days pride. It's sort of a rite of passage. |
|
Heres a sample "Record holder" that I used last year in school as a group project: // The file contains the record holder /******************************************************************** Record_Holder stores any type data, as long as it has a static member function file() that returns the location of the file. Also, the record needs to overload cout. Member functions so far: display() -- sequentially displays the data addData() -- appends new data to the ends of its respective file Functions to be put in: search() -- finds a specific file, should overload == in record classes sort() -- sort alphabetically or sequentially The only member data is size, which is saved in another file. size will be helpful for sorting. *********************************************************************/ template class Record_Holder { private: int size; public: Record_Holder(); ~Record_Holder(); void display(); // Displays all data void addData(T input); void search(T in); }; template Record_Holder< T >::Record_Holder() { ifstream Index( "index.dat" ); Index >> size; Index.close(); } template Record_Holder< T >::~Record_Holder() { ofstream Index( "index.dat" ); Index << size; Index.close(); } template void Record_Holder< T >::display() { ifstream inData( T::file(), ios::in ); if( !inData ) { cerr << "File could not be opened." << endl; exit(1); } T lookatme; inData.read( reinterpret_cast sizeof( T ) ); while( inData && !inData.eof() ) { cout << lookatme; inData.read( reinterpret_cast sizeof( T ) ); } } template void Record_Holder< T >::addData( T input ) { ofstream outData( T::file(), ios::app, ios::binary ); if( !outData ) { cerr << "File could not be opened." << endl; exit(1); } outData.seekp( size * sizeof( T ) ); outData.write( reinterpret_cast sizeof( T ) ); size++; outData.close(); } |
|
gun owning computer nerds [:)] I should graduate with a BS in CS at the end of this semester Quoted: Mattja, Nice use of an array! I can't get over the diversity that make up the members of this forum. Just a couple of days ago, there was an audiophile discussion on high end loud speakers and now C++??? Glad to see this forum is not just a typical firearms discussion site. |
|
Quoted: Mattja, Nice use of an array! I can't get over the diversity that make up the members of this forum. Just a couple of days ago, there was an audiophile discussion on high end loud speakers and now C++??? Glad to see this forum is not just a typical firearms discussion site. Yep, we have a diverse crowd over here. We aren't all drooling gun nuts as the media would have people believe. :) |