Buddy System (partner system) algorithm in heap management algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.