The following is a detailed description of the dlmalloc algorithm: http://g.oswego.edu/dl/html/malloc.html
The dlmalloc part is reserved by some metadata, which includes information about the amount of space in the piece. Two adjacent free pieces may look like
[metadata | X bytes free space | metadata ][metadata | X bytes free space | metadata] Block A Block B
In this case, we want to combine block B into block A. Now how many bytes of free space should the report block?
I think it should be 2X + 2 size(metadata) bytes , since now the merged block looks like this:
[metadata | X bytes free space metadata metadata X bytes free space | metadata]
But I wonder if this is correct, because I have a tutorial that says that metadata will report 2X bytes , not including the extra space that we get from being able to write on metadata.
memory-management unix malloc
Mark
source share