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

NOTE WHEN YOU DO THE QUESTION PLEASE ALSO WRITE A EXPLANTION HOW YOU DO THE EQUA

ID: 3877553 • Letter: N

Question

NOTE WHEN YOU DO THE QUESTION PLEASE ALSO WRITE A EXPLANTION HOW YOU DO THE EQUATION

Assume we are working on a system that has 1KB of memory available for the heap (Yes, it's pretty small but let's work with this as it makes the problem more tractable for an exam). Using the dynamic memory allocation algorithms we used in class, give the address returned for each of the memory requests. If the memory request cannot be satisfied then return 0 and stop. 1. Request Allocate A 128 Allocate B 512 Free A Allocate C 128 Allocate D 256 Free B Allocate E 64 Allocate F 256 Allocate G 256 Free F Allocate H 160 Allocate J 64 First Fit Best Fit Worst Fit

Explanation / Answer

1KB = 1024 bytes
HH - stands for hole
Whenever allocation and deallocation happens, new partitions get created and consumed accordingly


The Allocations are as follows:
Request         First Fit     Best Fit        Worst Fit
Allocate A 128     1            1                1
First Fit Partition: 128(A) 896(HH)
Best Fit Partition: 128(A) 896(HH)
Worst Fit Partition: 128(A) 896(HH)

Allocate B 512     1            1                1
First Fit Partition: 128(A) 512(B) 384(HH)
Best Fit Partition: 128(A) 512(B) 384(HH)
Worst Fit Partition: 128(A) 512(B) 384(HH)

Free A
First Fit Partition: 128(HH) 512(B) 384(HH)
Best Fit Partition: 128(HH) 512(B) 384(HH)
Worst Fit Partition: 128(HH) 512(B) 384(HH)

Allocate C 128     1            1                1
First Fit Partition: 128(C) 512(B) 384(HH)
Best Fit Partition: 128(C) 512(B) 384(HH)
Worst Fit Partition: 128(HH) 512(B) 128(C) 256(HH)

Allocate D 256     1            1                1
First Fit Partition: 128(C) 512(B) 256(D) 128(HH)
Best Fit Partition: 128(C) 512(B) 256(D) 128(HH)
Worst Fit Partition: 128(HH) 512(B) 128(C) 256(D)

Free B
First Fit Partition: 128(C) 512(HH) 256(D) 128(HH)
Best Fit Partition: 128(C) 512(HH) 256(D) 128(HH)
Worst Fit Partition: 128(HH) 512(HH) 128(C) 256(D)

Allocate E 64     1            1                 1              
First Fit Partition: 128(C) 64(E) 448(HH) 256(D) 128(HH)
Best Fit Partition: 128(C) 512(HH) 256(D) 64(E) 64(HH)
Worst Fit Partition: 128(HH) 64(E) 448(HH) 128(C) 256(D)

Allocate F 256     1            1                1        
First Fit Partition: 128(C) 64(E) 256(F) 192(HH) 256(D) 128(HH)
Best Fit Partition: 128(C) 256(F) 256(HH) 256(D) 64(E) 64(HH)
Worst Fit Partition: 128(HH) 64(E) 256(F) 192(HH) 128(C) 256(D)

Allocate G 256     0            1                0
First Fit Partition: 128(C) 64(E) 256(F) 192(HH) 256(D) 128(HH) (G fails in first fit and hence stops)
Best Fit Partition: 128(C) 256(F) 256(G) 256(D) 64(E) 64(HH)
Worst Fit Partition: 128(HH) 64(E) 256(F) 192(HH) 128(C) 256(D) (G fails in worst fit and hence stops)

Free F                         
Best Fit Partition: 128(C) 256(HH) 256(G) 256(D) 64(E) 64(HH)

Allocate H 160                  1         
Best Fit Partition: 128(C) 160(H) 96(HHH) 256(G) 256(D) 64(E) 64(HH)

Allocate J 64                   1         
Best Fit Partition: 128(C) 160(H) 96(HH) 256(G) 256(D) 64(E) 64(J)