Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objectives After this lab, students should be able to implement a modified linked list for memory management. Background A traditional free list only contains unused
Objectives After this lab, students should be able to implement a modified linked list for memory management. Background A traditional free list only contains unused regions of an address space. A modified list may include both used (allocated) and unused regions of the address space The overhead for maintaining the modified list is the same for both types of regions, and is as follows typedef struct node t int size; int free; structnode t *next; //pointer to next region //size of region //1 == free; 0 == used node t The modified list has some features that makes its implementation easier Prevents memory leak (keep track of allocated memory, even if the requester doesn't) Uniform overhead siz Linked list always stays in sequential order (in terms of memory address) Instructions Write a program in C named coalesc.c that simulates a dynamic memory allocation system, with the following requirements: Accept a commandline argument for the size of the heap to be simulated and use the malloc () system call to make space for the given size Give the user a menu of options * 1. malloc: Allocate memory within the heap for N bytes 2. free: Deallocate memory from the heap using relative address 3. coalesce: Detect and remove adjacent free regions 4. view: Traverse the free list and print its information as well as total overhead in bytes 5. quit: Exit the program heap: 12722192, 0 ALLOCATOR: ENTER AN OPTION 2. Iree 3. Coalesce 4. vieiw 5. quit CHOICE: 1 ENTER THE SIZE IN BYTES: 2000 ALLOCATOR: ENTER AN OPTION 1. malloc 2. Iree 3. coalesce 4. view 5 quit CHOICE: 1 ENTER THE SIZE IN BYTES: 2500 ALLOCATOR: ENTER AN OPTION 2. Iree 3. Coalesce 4. view 5 quit CHOICE: 3 ALLOCATOR: ENTER AN OPTION 1. malloc 2. Iree 3. coalesce 4. vieiw 5. quit CHOICE: 4 Traversing linked list of free regions. . . vAddr-12722192, offset-0, size-4984, free-1 Total overhead: free regions:1 (16 bytes per) used regions:0 (16 bytes per) 16 bytes Objectives After this lab, students should be able to implement a modified linked list for memory management. Background A traditional free list only contains unused regions of an address space. A modified list may include both used (allocated) and unused regions of the address space The overhead for maintaining the modified list is the same for both types of regions, and is as follows typedef struct node t int size; int free; structnode t *next; //pointer to next region //size of region //1 == free; 0 == used node t The modified list has some features that makes its implementation easier Prevents memory leak (keep track of allocated memory, even if the requester doesn't) Uniform overhead siz Linked list always stays in sequential order (in terms of memory address) Instructions Write a program in C named coalesc.c that simulates a dynamic memory allocation system, with the following requirements: Accept a commandline argument for the size of the heap to be simulated and use the malloc () system call to make space for the given size Give the user a menu of options * 1. malloc: Allocate memory within the heap for N bytes 2. free: Deallocate memory from the heap using relative address 3. coalesce: Detect and remove adjacent free regions 4. view: Traverse the free list and print its information as well as total overhead in bytes 5. quit: Exit the program heap: 12722192, 0 ALLOCATOR: ENTER AN OPTION 2. Iree 3. Coalesce 4. vieiw 5. quit CHOICE: 1 ENTER THE SIZE IN BYTES: 2000 ALLOCATOR: ENTER AN OPTION 1. malloc 2. Iree 3. coalesce 4. view 5 quit CHOICE: 1 ENTER THE SIZE IN BYTES: 2500 ALLOCATOR: ENTER AN OPTION 2. Iree 3. Coalesce 4. view 5 quit CHOICE: 3 ALLOCATOR: ENTER AN OPTION 1. malloc 2. Iree 3. coalesce 4. vieiw 5. quit CHOICE: 4 Traversing linked list of free regions. . . vAddr-12722192, offset-0, size-4984, free-1 Total overhead: free regions:1 (16 bytes per) used regions:0 (16 bytes per) 16 bytes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started