Aeron Flores and Jasmine Rasmussen
CS480 Summer 2024
Assignment 3, README
Sim is a program that simulates memory allocation and deallocation on an operating system using a linked list. This program has a handful of built-in functions:
- BestFit: allocateMem, deallocateMem, and fragmentCount
- lets users allocate and deallocate memory based on the best fit algorithm and also uses the fragmentCount class to count for fragments in memory
- First Fit: allocateMem, deallocateMem, and fragmentCount
- lets users allocate and deallocate memory based on the first fit algorithm and also uses the fragmentCount class to count for fragments in memory
- generateRequest
- includes random number generation for generating allocation and deallocation and number of units to be requested dynamically
- stats
- produces the following for each memory model:
- Average External Fragments Each Request
- Average Nodes Traversed Each Allocation
- Percentage Allocation Requests Denied Overall
- produces the following for each memory model:
Files/Folders included in a3.zip:
README.md: Details on the program and how to run itMakefile: Makefile used to compile thesimexecutablebest_fit.cpp: Derived class ofMemoryManagement; Contains functions for best fit allocation and deallocation algorithm and fragment countfirst_fit.cpp: Derived class ofMemoryManagement; Contains functions for first fit allocation and deallocation algorithm and fragment countgenerate_request.cpp: Generates the process IDs and units requested for the processes; Also generates whether process is allocated or deallocatedgenerate_request.h: Header file forgenerate_request.cppmain.cpp: Main source file that outputs results for first fit and best fit based on the number of requests.memory_management.h: Header file forbest_fit.cppandfirst_fit.cppstats.cpp: Generates statistics for Best Fit and First fit memory modelsstats.h: Header file forstats.cpp
To compile the program, G++ v.4.8.5 (or a similar compiler) that compiles C++11 is needed.
- Download
a3.zipand extract the files to a directory of your choice. - Once finished, open your terminal and navigate to
a3. To navigate to the directory:- Windows Command Prompt (cmd)/PowerShell:
cd Drive:\path\to\directory\a3 - MacOS:
cd /path/to/directory/a3 - Linux/UNIX:
cd /path/to/directory/a3
- Windows Command Prompt (cmd)/PowerShell:
- Navigate to folder
/a3 - Run command
maketo create the executablesim.
Program sim is ready to be used! Run the program using the following commands:
- Windows Command Prompt (cmd):
sim - Windows PowerShell:
.\sim - Linux/UNIX/MacOS:
sim
NOTE:
Command make clean will remove any generated object files and executables.
------------------- FIRST FIT ---------------------
Average Number of External Fragments: 0.0216539
Average Allocation Time (nodes traversed): 14.7484
Percentage of Allocation Requests Denied: 30.92%
-------------------- BEST FIT ---------------------
Average Number of External Fragments: 0.0173031
Average Allocation Time (nodes traversed): 31.0846
Percentage of Allocation Requests Denied: 29.32%
The project is organized into multiple source files, each handling specific parts of the sim functionality. This modular design helps with code readability, maintainability, and the facilitation of easier debugging and testing.
First Fit and Best Fit builds upon the modular design by separating their logic and the data they send and receive. This makes it easier to modify each memory model without affecting others. They also utilize an abstract base class MemoryManagement. This design allows for future memory models to be implemented if need be.
Random values are generated for determining the amount of units of memory each process will request. Each unit of memory contains 2 KB of space and each process can request a minimum of 3 units up to a maximum of 10 units of memory. If there is no memory available, allocation requests are subsequently logged.
-
Memory Fragmentation Not Correctly Merged: The fragment_count function might return excessive fragmentation or have a lack of memory.
-
Incorrect Handling of Edge Cases in Allocation: The allocation function has the possibility of not correctly handling edge cases such as those where the memory is full or when small fragments are available.
-
Effective Collaboration and Teamwork: Working in pairs for this assignment showed the need for clear communication and working together on tasks. We learned that regular code reviews and pair programming sessions on the Discord app can greatly enhance code quality and team productivity. There was a lot of debugging and problem solving done by us that required good teamwork.
-
Emphasis of Efficient Data Structures: In this project, using a linked list for managing memory blocks was an effective choice since it allowed dynamic memory allocation and deallocation. It was not an easy task to figure out fragmentation and traversing the list for allocation requests.
-
Good Error Handling and Edge Case Management: It is important in implementation to handle edge cases like fully occupied memory or unusable fragments which could lead to errors or crashes. Implementing error handling makes sure the code is stable.
-
Modularity Using Inheritance: By separating the logic of First Fit and Best Fit from the request generation and stats components, the program was easier to manage when modified and tested.
-
Soruce Control and Documentation: The authors of this project chose to make use of source control tools such as Git and Github in order to handle the evolving nature of this program. This taught us that clear comments and documentation were useful in organizing the code for more clarity so that both of us could understand the code.