You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to answer the homework in the book, but I always run into some questions (for example, my written answers don't match the computer answers). So I am wondering if there is a forum where I can discuss these questions? Please tell me, Thanks!
ex. Question 1 of Homework 17th Free Space. Why the value of sz is 88(I think is 92). I don't know why and I want to figure it.
The text was updated successfully, but these errors were encountered:
@BILY5354 in this case, you need to consider the operations which have been run to get to this point and the constraints you have put in place through the command line args.
The allocator is configured to give out chunks of memory of size 4 (using the -a 4 flag), so the first step hands out a pointer to a chunk of memory of size 4, which satisfies the request with 1 unit of memory wasted.
The call to Free(ptr[0]) puts the memory chunk of size 4 allocated in the first step back into the free list, so you have two entries of size 4 and 96.
The third step allocates more memory, and hands out a pointer to a chunk of size 8 to satisfy the request for 5. Because you have specified to use the Best Fit Policy with -p BEST, the allocator will choose to split the chunk of memory which will best satisfy the request. In this case, it's the second entry in the free list with size 96, and the pointer returned will point to a chunk of memory of size 2 x 4 = 8, i.e., 96 - 8 = 88. The total amount of free memory in the free list is now 4 + 88 = 92.
More concretely:
ptr[0] = Alloc(3)
# Allocated a chunk of size 4, free list now has 1 entry of size 96.
free(ptr[0])
# Put back the chunk, free list now has two entries of size 4 + 96 = 100.
ptr[1] = Alloc(5)
# Allocated a chunk of size 8 by splitting the entry in the free list with size 96, free list now has two entries of size 4 + 88 = 92.
sz
is 88(I think is 92). I don't know why and I want to figure it.The text was updated successfully, but these errors were encountered: