Question: Write a C++ program that emulates the operating system's responsibility of allocating memory to certain programs. On startup. Your program reads the text file IoT_device_data.txt
Write a C++ program that emulates the operating system's responsibility of allocating memory to certain programs.
On startup. Your program reads the text file "IoT_device_data.txt" into the funtion "allocate(string filename, int method)" which you will be implementing.
It should then allocate memory according to the 3 placement algorithms(best fit, worst fit, first fit). You will be implementing these functions too.
It should follow the output example given below. The main.cpp and allocator.cpp files are given only implement the following functions.


allocator.cpp
#include
using namespace std;
char** kilo; char** halfkilo; char** quaterkilo; int numberOfBlocks = 5;
void printArray(char** arr, int size) { cout
tmp = percentage * bsize; for (int k = 0; k
void visualize(int type = 0) { cout
// Functions to implement are below this line, Do not modify the code above this line you will receive no marks otherwise!!! // =========================================================================================================================
void initialize() { // @TODO initialize the 3 char** arrays with the numberOfBlocks value // Tip: 1 char value is 1 byte. }
void destroy() { // @TODO deallocate all the allocated memory in the initialize function // Tip: Don't leave dangling pointers }
void bestfit(string data) { // @TODO data - is the data to write to the 3 arrays // Tip: The smallest block that can fit the required size visualize(0); }
void firstfit(string data) { // @TODO data - is the data to write to the 3 arrays // Tip: The first available block that can fit the required size visualize(1); }
void worstfit(string data) { // @TODO data - is the data to write to the 3 arrays // Tip: The biggest block that can fit the required size visualize(2); }
================================================================================================================= main.cpp
#include "allocator.cpp"
void allocate(string filename, int method) { // @TODO implement this function }
int main(int argc, char const *argv[]) { allocate("IoT_device_data.txt", 2); return 0; }
==============================================================================================================================
IoT_device_data.txt
A: IoT device A with data ialNzXFercGEDWQxHYjlR7su10HpfI1P28FPEuqit2DtbFtSXijYYWRK/M2yBRL5SZSIkJFcpNIrkkA0rviphKBXNtds5PF56r5qe6nnKkvl/P+0ciXzjGVKocXvxdgRvyKqV45mA6kK2c596wFiojEwbPqDwp5aHcOc6ElaUZKfC0NycBto5Y8ar8I7UUARzM8ts7rfYLW5bs3WR8jljrMpTW1Pwo+sHHOh3oDEUiiDCBh8XqlAnvLyZaYdarrE B: IoT device B with data ialNzXFercGEDWQxHYjlR7su10HpfI1P28FPEuqit2DtbFtSXijYYWRK/M2yBRL5SZSIkJFcpNIrkkA0rviphKBXNtds5PF56r5qe6nnKkvl/P+0ciXzjGVKocXvxdgRvyKqV45mA6kK2c596wFiojEwbPqDwp5aHcOc6ElaUZKfC0NycBto5Y8ar8I7UUARzM8ts7rfYLW5bs3WR8jljrMpTW1Pwo+sHHOh3oDEUiiD2MndY3fotjh0NuTl9QiZ C: IoT device C with data x4vIHjv5UHNUMzqUVG35TOTUCikDe1sLafGs7Gugqhz5MakgOA5+LDEsdVi5cOE+GaevWutNvlEVPZ00it2XUjElClflFekQMZEunYWglCOD0BvwTJiEMikdRn46kQQF1JY7qgZHA9XFqWFyD9gjCNRBAmsqcKxz6s7Mwohyh2PS6fGQzANQHr9BFb8O/iB2rndG9KmIP6PRNtlxwhZnlcJuiVaaXbysBInfDnMRt9pfGZT+wWaMox2fU81e4N85fNmbhtbdViFWjVlihBZqHhMbS20LngANZXqfqMXHvYj3jTv+h/IIAT75NAObLw05lf3VmMQsYbO5c1Zn7pK5H/sGta5IH6kSWFEPrILoJohSqlCdv3vLYkofGDi18y D: IoT device D with data MBZXRcqOUseiKzDaz8qC+TV4g8sSIf98fsSPoixnTrjEuDYftILdBHVmBq6GKavRtysgpD/pFwoGxIWYPlN+iOzAbQnIs2M5cHdD3I8ajZcUS/Tm/iWPFB0JBhF1mqYy6Ie/OEuVfyShpaB/fjuSO8nRjt4LGuTlOY+J3JtZUq8x926TThi2Z9nY0vrw5hBOD38TbGSXIlK6ezxeHAIXzakLFhuKcGyikUJMHdfjeYrZ23vIuzYHV8xeSSMlNfBdJzzqtpmU0pn39O9WOuYv1ttIXsDNs9AA7SN09Q5vWDov+9mP7rLoYYgSzjZARIyg E: IoT device E with data FzaMHyi7xDIAxBNF7F/SSIbH+WCU/4PP12qbGLhxUaA6iKFEvq9sk41Bc5UjizT4GewnSffpnQq+nVsYoIoQqzL2Iz6A/fW3Ujc9cXGDRk3oOn3isgWW0FTwg8WlMZHvfXUCAfu22ge7B8nCpgJLEHSj8Yfl5wleik0//YCv5EkhKit6H8fRvUOiudS4EXDBPqv/sjvPKZtrhqVeOk5WWQ== F: IoT device F with data FzaMHyi7xDIAxBNF7F/SSIbH+WCU/4PP12qbGLhxUaDPoo7YMUfqlZ87pMj7B6VUGV1I5pnkw+yyLALjbexd4AzNcrTGn3OOOJmz2VrDaZs5an3MlhMn7NYzyrgPS3KbO0ILn1OAyoM2GJoZ7SvxJe5iAoWBmFEp5/9juPedBRSeVlKYp2nm2eLW/WSz31F+LVdunDG07QIjIF4uCNP7tqGlB6CHnMSEOT1CVZo/Z4JT1iytmyDvv4GwCm2TW5k8hjoQwiruHoCte8ABwmpqozxT/8x86yVmFIz7SnEUK2P7hwrYV62bFCXksFfGtDsbtYOzr9jjdVjgKYUwyfr1I31K3H83ylHaa3jQDWE6sxnWe1u7XwdeDSpuwAdVl+ZjuUGR7/5SS/HEjEPG6Af1NhHnEDUzRseu4ZmmxChcXCpiqBIMVhK5MaIMh5JG32TvRJ28Jxe+NNfwFJuMJzewLbj5hveKGzDE/g33rr4IHWlFhJhRcBFxvFyi5KOUPl9+
You are not allowed to edit any of the given functions. Functions to implement: 1. initialize) you will se that there are 3 char** arrays, [kilo, halfkilo, quaterkilo] each of these arrays wil contain numberOfBlocks as the number of blocks, which default value is 5. You will then nocd to create 5 blocks for each aray and initialize them as described below. (a) kilo - for each block in this array you will neel to allocate 1024 bytes. (b) halfkilo for each block in this array you will need to allocate 512 bytes. (c) quaterkilo for each block in this array you will need to allocate 236 bytes. Hint: Since this is a dynamic 2D array and char reprosents 1 byte you can easily allocate the space accordingly with new or malloc. To make things easier only empty blocks should be considered when doing allocation using the 3 algoritlms. 2. destroy) yo il d to deallocate all the allocated space to the 3 arrays. Be 3. bestfit(string data) the parameter defines te data to be written to the 3 4. firstfit(string data) - the parameter defines the data to be written to the 3 arrays 5. worstfit(string data) t parameter defins t data to be written to the 3 6, allocate(string filename, int method)-this function is to be implemented in aware not to leave dangling pointers or unallocated memory, arrays depending on the bostfit algorithm which you have to implement depanding on the firstfit algorithm which you have to implement. arrays depending on the worstfit algorithm which you have to implement. your main.epp file, the first parameter is the filename which should be read line by line calling the desired memory management algorithm. the second parametei takes the algorithm method type ( bestfit, 1 worstfit, 2 - firstfit) Note: For the above 3 algorithms the data that should be written to those blocks is read from a text file in the main.epp (each line represents one IoT device data) You may use additional helper functions if you wish too, however allowed to edit the given code. You have been provided with a small main file in which you can use for testing. You are roquired to do significant amount of testing involving all the algorithms. Hint: Two of the algorithms wll perform somewhat similar, you need to explain why this happens in your deno you are not Here is an example of the output from the provided main file with the allocate function implemented, only the last call to the function is displayed below (i.e after all the IoT devices have been allocated)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
