HW1

.pdf

School

Purdue University *

*We aren’t endorsed by this school

Course

252

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

14

Uploaded by AmbassadorOyster2629

CS252 Homework 1 (ver2) 1. Given we have an arena size of 128, what would be the correct memory diagram from the following code snippet if we are using the myMalloc library from lab1. Assume that when an object is split, the left part is returned by malloc and the right part stays in the free list. char * ptr1 = malloc(14) char * ptr2 = malloc(42) char * ptr3 = malloc(6) free(ptr2) free(ptr1) char * ptr4 = malloc(79) Here is a blank diagram for your work:
2. In the following program, which memory section does the address &p reside in: int a = 5; int b[20]; int main() { int x; int *p =(int*) malloc(sizeof(int)); } Answer: _______________ 3. According to the memory configuration represented in the diagram below: if the user makes a call to malloc(num_of_bytes) , what is the smallest value num_of_bytes can be to trigger a call to sbrk() . The shaded area indicates the allocated memory. Answer: _______________
4. Dark shaded blocks are allocated, white blocks are unallocated, and fence posts are indicated by "F". Assume block A was allocated and then freed. After block A is freed, what memory address points to the header associated with the memory that will contain A, and what is the size of the block? Answer:_____________ 5. Dark shaded blocks are allocated, white blocks are unallocated, and fence posts are indicated by "F". The user calls free on block A. After block A is freed, what memory address points to the header associated with the memory that contains A, and what is the size of the block? Assume block A was allocated before being freed. Answer:____________
6. Dark shaded blocks are allocated, white blocks are unallocated, and fence posts are indicated by "F". Assume a 64-bit architecture. The user calls free on block A. After block A is freed, what memory address points to the header associated with the memory that contains A, and what is the size of the block? Assume block A was allocated before being freed. Answer:________ 7. In the malloc implementation, we had a global variable: "header * lastFencePost", What was this variable used for? Answer:
8. What are the benefits of using boundary tags as a data structure for memory allocation. Answer: 9. The following code is an example of int main() { int *p = ( int * ) malloc ( 100 ); p = p + 1; free(p); return 0; } Answer: 10. Use this simplified diagram of the free lists as reference. The numbered blocks are sentinels, the lettered blocks indicate free blocks. Use the segregated free list indexing from the lab1 handout. Which block would be chosen to satisfy a malloc of size 8?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help