In a buddy system algorithm, the heap manager allocates only a block of memory of a specific size and becomes permitted size. For each permitted size, there is a free list to maintain.
In general, these sizes will select the power of 2, or the Fibonacci sequence. Because it is convenient to divide the number of other than the smallest number into the sum of two permitted size.
When the heap manager responsible for allocating memory accepts a request for memory of size S, the S-aligned to a permitted size is spoken. Then allocate a piece of memory from that permitted size's free list to him. If the memory is not found in that free-link list, a chunk of memory is allocated to the user in large-scale memory, and the remaining half is then hung to the idle list of the permitted size.
The idle list in this algorithm is generally implemented by using the bitmap (bitmap) algorithm. This makes it very efficient to merge memory collections.
Using the partner system algorithm in the heap management algorithm in the Zend engine, we take a look at the related data structures in the ZEND_MM_HEAP structure:
Zend_mm_free_block *free_buckets[zend_mm_num_buckets*2];
This free_buckets is a two-bit array of idle lists. Zend_mm_num_buckets defines the maximum power value at the time of allocation. Each power value corresponds to a *free_buckets, which is an idle list.
Buddy System (partner system) algorithm in heap management algorithm