Summary of C + + technical Issues-8th how STL memory pools are implemented

Source: Internet
Author: User

STL memory pool mechanism, using a dual-level configurator. The first level uses malloc, free, and the second level uses different strategies depending on the situation.

Such a mechanism takes space from the heap and can resolve memory fragmentation issues.


1. Memory Application Flowchart
A brief flowchart such as the following.


2. Second Level configurator description
    second level configurator to resolve memory fragmentation problems caused by small chunks.


    Use the free list (free-list) technique. Proactively raise the memory requirements of any small chunk to multiples of 8. If demand is 30, increase to 32.
    free-list node structure
    Union obj
    {
        Union obj* Free_list_link;
        Char client_data[];
   };
    has 16 free-lists. The respective management sizes are 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, and bytes of small chunks.
    application process such as the following.

    release process such as the following.


Summary of technical issues with C + +-8th How STL memory pools are implemented

Related Article

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.