Question: This problem is intended for C/C++, but i only know a bit of python and im having some trouble. Can somebody help me out with

This problem is intended for C/C++, but i only know a bit of python and im having some trouble. Can somebody help me out with this code and write the answer in python or explain it better? Thank you!

Simulation: Main Memory Allocation (Shivakant Mishra)

Goal: To simulate and evaluate different memory allocation/deallocation techniques, first fit, next fit, best fit, and worst fit, when a linked list is used to keep track of memory usage. Assume that the memory is 256 KB and is divided into units of 2 KB each. A process may request between 3 and 10 units of memory. Your simulation consists of three components:

Memory component that implements a specific allocation/deallocation technique;

request generation component that generates allocation/deallocation requests;

and statistics reporting component that prints out the relevant statistics. The Memory component exports the following functions:

1. int allocate_mem (int process_id, int num_units): allocates num_units units of memory to a process whose id is process_id. If successful, it returns the number of nodes traversed in the linked list. Otherwise, it returns -1.

2. int deallocate_mem (int process_id): deallocates the memory allocated to the process whose id is process_id. It returns 1, if successful, otherwise 1.

3. int fragment_count( ): returns the number of holes (fragments of sizes 1 or 2 units).

You will implement a separate Memory component for each memory allocation/deallocation technique. The request generation component generates allocation and deallocation requests. For allocation requests, the component specifies the process id of the process for which memory is requested as well as the number of memory units being requested. For this simulation, assume that memory is requested for each process only once. For deallocation requests, the component specifies the process id of the process whose memory has to be deallocated. For this simulation, assume that the entire memory allocated to a process is deallocated on a deallocation request. You may generate these requests based on some specific criteria, e.g. at random or from a memory allocation/deallocation trace obtained from some source.

There are three performance parameters that your simulation should calculate for all four techniques: average number of external fragments, average allocation time in terms of the average number of nodes traversed in allocation, and the percentage of times an allocation request is denied.

Generate up to 10,000 requests using the request generation component, and for each request, invoke the appropriate function of the Memory component for each of the memory allocation/deallocation technique. After every request, update the three performance parameters for each of the techniques.

The statistics reporting component prints the value of the three parameters for all four techniques at the end.

This is all the information I have.
.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!