next up previous contents index
Next: free() routine Up: C Heap Allocation Model Previous: C Heap Allocation Model

malloc() routine

 

In the dlmalloc's malloc() routine, a chunk is the unit of allocation. A chunk can be allocated or free. At the head of each chunk, a structure chunk is placed. In each chunk, there are the size of the chunk, and the size of the previous chunk. In a free chunk, pointers to the forward and the backward free chunk are also contained.

When a memory block is requested, malloc() finds out an appropriate free chunk and split it for allocation. Every free chunk is a member of one of the doubly-linked list of free chunks called bins. In each bin, free chunks whose sizes are within a specific range is chained in order of their sizes. Searching for an appropriate free chunk is optimized by these bins.



Mori Tetsuya / t2y3141592@gmail.com