I have a C memory allocator implemented with a circular linked list. The blocks in the freelist are address-sorted. Every time a block is returned to the freelist, the list is iterated to find the proper position to insert and merge with adjacent blocks?
The question is: is there a way to improve the free() operation in terms of performance so that it does not need to iterate through the whole list every time to find the position to insert the block?
I got this question asked in an interview today and had no idea. Can we use a hash or something?
There are many ways to try and optimize access to items in an ordered list.
free()
function, especially in a multi-threaded environment.This allocation strategy does not seem to have any real advantage over classic arena based doubly linked lists or size bins with simple local free lists.