Question: Write a C++ program to emulate the different memory placement algorithms. Implement the following functions: main.cpp #include allocator.cpp void allocate(string filename, int method) { //
Write a C++ program to emulate the different memory placement algorithms.
Implement the following functions:


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; }
=====================================================================================================================
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() {
kilo = (char **)malloc(sizeof(char *) * numberOfBlocks );
kilo[0] = (char *)malloc(sizeof(char) * 1024 * numberOfBlocks );
halfkilo = (char **)malloc(sizeof(char *) * numberOfBlocks );
halfkilo[0] = (char *)malloc(sizeof(char) * 512 * numberOfBlocks );
quaterkilo = (char **)malloc(sizeof(char *) * numberOfBlocks );
quaterkilo[0] = (char *)malloc(sizeof(char) * 256 * numberOfBlocks );
}
void destroy() {
for (int i = 0; i
for (int i = 0; i
for (int i = 0; i
}
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); }
================================================================================================================
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+
3. bestfit(string data) the parameter defines the data to be writen to the 3 4. firstfit(string data) the paraeter defines the data to be written to the 3 arrays . worstfit(string data) the parameter deinas te datto be written to the 3 6. allocate(string filename, int method) this functi to be implemented in arrays dopending on the bastfit algorithm which you have to implement depending on thc firstfit algoritlhn which you have to imploment. arrays depending on the worstfit algoritlim which you have to implement. your main.epp file, tlie first paraneter is the filenane which should be read linie by line calling the dosirel meimory managcinent algorithm. the second parametor takes the algorithn method type (D - bestfit, 1 - worstfit, 2 - firstfit) Note: For the above 3 algoritlhms the data that should be written to those blocks is read from a text file in the main.cpp (each line represents one IoT device data) You may use addlitional helper functions if you wish too, however allowl to edit the given code. You hav ben provided with a main file irn which you can use for tosting. You are required to do significant amount of testing involving all the algoritlhms. Hint: Two of the algoritms will perform somewlhat similar, yo you are not u need to explain why this happens in your demo. Here is an oxample of the output from the provided main file with the allocate function implomente y the last call to the function is displayed below (i.e after all the IoT devicos havo heen allocated
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
