mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Fill in images related to merging freed blocks
This commit is contained in:
@@ -768,13 +768,13 @@ In contrast to the bump allocator, the linked list allocator is much more suitab
|
||||
|
||||
The main problem of our implementation is that it only splits the heap into smaller blocks, but never merges them back together. Consider this example:
|
||||
|
||||
TODO
|
||||

|
||||
|
||||
In the first line, three allocations are created on the heap. Two of them are freed again in line 2 and the third is freed in line 3. Now the complete heap is unused again, but it is still split into four individual blocks. At this point, a large allocation might not be possible anymore because none of the four blocks is large enough. Over time, the process continues and the heap is split into smaller and smaller blocks. At some point, the heap is so fragmented that even normal sized allocations will fail.
|
||||
|
||||
To fix this problem, we need to merge adjacent freed blocks back together. For the above example, this would mean the following:
|
||||
|
||||
TODO
|
||||

|
||||
|
||||
In line 3, we merge the rightmost allocation, which was just freed, together with the adjacent block representing the unused rest of the heap. In line TODO, we can merge all three unused blocks together because they're adjacent, with the result that the unused heap is represented by a single block again.
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 29 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 25 KiB |
Reference in New Issue
Block a user