Open monzurularash opened 2 years ago
This looks like the case, I will look into this further and update this thread in the next few weeks.
I think the original code from the instructor was correct. If you remove the - 1, you'll incorrectly mark the last block in a sequence as being Taken | Has-Next.
Breakpoint 3, heap_mark_blocks_taken (heap=0x103028
As you step through the for-loop, the value of the heap->table->entries[i], for 5 blocks progresses like:
[193] [129] [129] [129] [1] <- entry values in decimal [FTH] [TH] [TH] [TH] [T] <- entry attributes [0] [1] [2] [3] [4] <- indices
I have a confusion about a function at heap.c. Does following line at function heap_mark_blocks_taken() has "off by one" error?
if (i != end_block -1) { entry |= HEAP_BLOCK_HAS_NEXT; }
Should it be following instead:
if (i != end_block ) { entry |= HEAP_BLOCK_HAS_NEXT; }
/*
for example: if total_block =4 and start_blok =0, so end_block=3
so we want to mark(set) the block0, block1 and block2 with flag HAS_NEXT.
*/