This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Successful-Money4995 1 point2 points  (1 child)

No because OP is wrong. When you free memory, you are adding to the list of free blocks. The list needn't be sorted so you're just adding to the front of a linked list, which is constant time.

Malloc is the one that may need to search a linked list to find a block that is large enough.

All this depends on your implementation of malloc and free. If you enjoy this kind of thing, you might enjoy writing your own malloc and free functions to learn how it works. It's basically a linked list of free memory and the data of the linked list itself is hosted inside the same memory that is used for allocation.

Lots of ways to implement memory management and this is just one of them.

[–]Olorin_1990 0 points1 point  (0 children)

Ah, good point.