virtual memory - dynamic memory allocation memory bugs 1. define internal fragmentation external fragmentation 2. explain differences between first-fit next-fit best-fit is first-fit faster or best-fit which does better in terms of fragmentation minimization 3. how does garbage collection work roughly? explain the mark and sweep algorithm. 3.1 why is garbage collection hard with the C programming language? 4. write code to show how malloc and free should be called. 5. what function does brk or sbrk play in the malloc system. 6. compare and contrast the following rough algorithms for malloc/free alg#1 malloc(n) { sbrk(n); } free(n) { } alg#2 malloc(n) search free space to see if improvements can be made to minimize future fragmentation search space of all known previous pointers to reap any unclaimed garbage allocate memory n based on a segregated free list scheme free(n) search space of all known previous points to reap any unclaimed garbage put the free block back and coalesce appropriately 7. with a free list structure, what are the four different cases for possible coalescing of free blocks. why is this constant time? 8. an implicit list has the following aspects: a. complex implementation b. simple implementation c. constant time in allocation d. linear time in allocation e. constant time in freeing blocks f. linear time in freeing blocks g. worst-case fragmentation i. used in all UNIX implementations for malloc/free j. usually found with boundary tag scheme k. in part used with UNIX e.g., list of used blocks and boundary tags 9. why is it useful to have a header and a trailer boundary tag in an implicit free list 10. true/false: 1. sbrk is never called with normal free() implementations 2. if the free list is empty, sbrk may be called to grow it 3. next-fit is a commonly used algorithm for finding free space 4. garbage collecting algorithms are always constant time 5. a segregated free list block class system can approximate best fit in terms of its ability to avoid fragmentation 11. what is the difference between int *size; *size++; size++; (*size)++; 12. explain what's wrong 1. int x; scanf("%d\n", &x); 2. #include main() { int N = 100; int i; int **p; p = (int **) malloc(N * sizeof (int *)); for ( i = 0; i <= N; i++) { p[i] = malloc(N * sizeof(int)); } } 3. main() { char s[50] gets(s); } 4. struct foo { unsigned long a; struct foo *next; }; struct foo *c[10]; c = malloc(10 * sizeof(struct *foo)); c += sizeof(struct foo));