I'm confused regarding heap and free list. I have a few questions and I have my own understanding of how malloc works in C. Please correct me if I'm wrong.
- Is the heap memory organized as a linked list (free list) of data blocks ?
- Is there a difference between heap memory and free list ?
My understanding of storage allocation (open for improvement) :-
When we call malloc, it allocates memory in the heap, and it does so by picking a data block of suitable size from the free list, right ?
When a certain block of memory is returned by malloc, it is removed from the free-list and the physical address of that block of memory is updated in the page table.
When the memory is free'd using free(), the data block is inserted back in the free-list, and possibly , to reduce fragmentation, conjoined with neighbouring block, and the present bit in the page table entry is cleared.
So the entire heap is a free-list(linked list of free blocks) + allocated data blocks .
Is that a comprehensive picture of storage allocation ?
EDIT : From Linux Kernel Development (Robert Love) Chapter on memory Management , Slab allocation
"A free list contains a block of available, already allocated, data structures. When code requires a new instance of a data structure, it can grab one of the structures off the free list rather than allocate the sufficient amount of memory and set it up for the data structure. Later, when the data structure is no longer needed, it is returned to the free list instead of deallocated. In this sense, the free list acts as an object cache, caching a frequently used type of object."
Free-list is mentioned as a "block of available, allocated data structure."
- How is it allocated, when it is in a free-list ?
- And how is returning a block of memory to free list _not_ the same as deallocating that block ?
- How is slab allocation different from storage allocation