Question: Note: all programs will be tested in a Unix environment (Windows Subsystem for Linux). Program #1 Memory Manager 15% Due: 03/02/2020 Assignment: Memory Manager In
Note: all programs will be tested in a Unix environment (Windows Subsystem for Linux).
Program #1 Memory Manager 15% Due: 03/02/2020 Assignment:
Memory Manager
In this assignment, you will be implementing the Memory Manager discussed in the textbook. You will need a struct that will serve as a header for an allocated section of memory and a struct that will server as a header for a contiguous section of free space.
typedef struct __mmalloc_t { ?? } mmalloc_t; typedef struct __mmfree_t { ?? } mmfree_t; mmfree_t* head; void* mem_manager_malloc(int size); void mem_manager_free(void* ptr); //traverse the free space list starting from the head, printing out info (for debugging) void traverse_free_list(); //called by malloc //find a free space chunk large enough for the requested allocation //obtain some memory from that chunk ?? locate_split(??); //called by free //locate the freed memory insert position so free space nodes are sorted by address ?? find_sorted_location(??); There is a minimum size allocation (for me, 8 bytes), below which your program will have issues due to header sizes. I will not be testing your program below this minimum amount.
To minimize fragmentation, when memory is freed, add the memory into the free list in sorted ascending order by address. This will allow you to check the free list nodes right before and right after and to merge the nodes if they represent contiguous memory locations.
Matrix Struct
You will use your memory manager to implement a matrix struct as follows:
typedef struct __matrix { int num_rows; int num_cols; double* elements; } matrix; matrix* matrix_malloc(int num_rows, int num_cols); void matrix_free(matrix* mat); void set_element(matrix* mat, int row, int col, double val); double get_element(matrix* mat, int row, int col); matrix* multiply(matrix* left, matrix* right); void display(matrix* mat); //left cols has to be the same as right rows for matrix multiplication matrix* multiply(matrix* left, matrix* right) { int left_rows = left->num_rows; int left_cols = left->num_cols; int right_rows = right->num_rows; int right_cols = right->num_cols; matrix* result = matrix_malloc(left_rows, right_cols); for (int i = 1; i <= left_rows; i++) { for (int j = 1; j <= right_cols; j++) { double val = 0; for (int k = 1; k <= left_cols; k++) { double element_left = get_element(left, i, k); double element_right = get_element(right, k, j); double mul = element_left * element_right; val += mul; } set_element(result, i, j, val); } } return result; } I will be using a driver to test your programs by creating, multiplying, and freeing matrices of various sizes in various orders, calling traverse to check your memory free list.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
