We saw four algorithms for
placing processes into holes in memory:
best fit, worst fit, next fit and first fit. Your job is to write
a simulator which will take processes of varying sizes, load them into
memory according to each of those rules, and swap processes out as
needed
to create a larger hole. Let us make the following assumptions:
You can use whatever data structure you wish (eg. linked list, bitmap) to simulate memory usage, but please make sure that the comments in the file clearly indicate what data structure you are using and how it is implemented. Each
time a process is requested to be in memory, print a line
such
as: #proc is the
number
of processes in memory When the last process has been killed, which will also be the
first time since the start that memory becomes empty, summary stats
should be printed: |
Sample
Input File
Fixed some numbers so that all "A"s would have the same size as each other. Also fixed the "C"s. ff A 30 B 20 C 75 A 30 D 80 C 75 A 30 D 80 A 30 C 75 B 20 A 30 C 75 B 20 E 55 B 20 kill B E 55 D 80 A 30 kill A E 55 kill E D 80 C 75 D 80 C 75 kill C D 80 kill D Sample
Run
|
|
Notes
The first line in the file will be either ff, wf, bf nf or ma (see below) For extra credit, design your own algorithm, including alternatives to LRU, if you wish, and see if you can consistently beat any or all of the four algorithms. The better your algorithm does, the more extra credit, up to 10 points, you will get. That's what the "ma" means up above. To make it easier on me, if you elect not to implement your own algorithm for the extra credit, then please have your program print a message such as "Not implemented," and then gracefully exit, whenever a file starting with "ma" is encountered. |