Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please explain Given the following sequence of calls to malloc and free *p4, *p5

ID: 3909431 • Letter: P

Question

Please explain

Given the following sequence of calls to malloc and free *p4, *p5, *p6, *p7; void *p1, *p2, *p3, p1 = malloc (40) ; p2 malloc (85) ; p3 malloc (30) ; free(p2); p4malloc (20); free(p3); p5 malloc (100) ; free(p1); free (p4); p6- malloc (10); p7- malloc (50); A. What is the maximum aggregate payload (Pmar)? (a) 100 (c) 160 (b) 125 (d) 335 B. Given a final heap size of 1024 bytes, what is the peak memory utilization? (b) Pnar/(1024 335) (d) 1024 -Pmar (a) Pmax/1024 max (c) Pma/(Pmaz 1024)

Explanation / Answer

maximum aggregate payload is the maximum memory used by the program.

free() frees the memory, thus we need to find the maximum memory used.

before free(p2), memory used = 40+85+30 = 155

before free(p3), memory used = 40+30+20 = 90

before free(p1), memory used = 40+20+100 = 160

before free(p4), memory used = 20+100 = 120

memory used at the end of program = 100+10+50 = 160

Thus, maximum aggregate payload Pmax is 160.

Peak memory utilisation is Pmax/Heap_size. Thus 160/1024 = 15.625%