Open k296070 opened 5 months ago
A1. Sentinels are there to help you distinguish the beginning and the end of the heap. Which content to fill in each sentinel is up to you.
Although you may distinguish the heap's beginning and end by using heap_start
and heap_end
, it is more consistent (in terms of coding) to use the sentinels as boundary conditions when traversing the whole heap. But depending on your implementation, you may or may not use sentinels.
Also, sentinels are called half-blocks since they only have a footer or a header - not because of their size.
A2. The given heap state should be constructed when mm_init
is called - not when mm_malloc
is called. In other words, after mm_init
, one huge free block should span the whole heap. After mm_malloc
, that one huge block should be split.
Thus, heap_start
and heap_end
are not identical to block_start
and block_end
. Only at the very beginning (right after mm_init
) will heap_start
and heap_end
point to the same address as block_start
and block_end
. After a series of mm_malloc
invocations, block_start
and block_end
will change, but heap_start
and heap_end
will consistently point to the beginning and end of the heap.
Thank you for correcting my misunderstanding!
Hello, I have some questions regarding the contents of the readme document. Q1. What are the initial sentinel half-block and end sentinel half-block? Why is the initial sentinel half-block in front of the Footer of preceding block, and end sentinel half-block is same as heap end. And also why it is named "half-block" although its size is just 1 word size.
Q2. I understood that if the ds_allocate function is called heap is created(ds_heap_start,ds_heap_brk) and then If I call malloc block is created(heap_start,heap_end). So doesn't term "heap_dtart,heap_end" supposed to be "block_start,block_end" ? I wonder if I am misunderstood.
Thank You!