"STL Source Analysis" Space Configurator

Source: Internet
Author: User

The spatial configurator (allocator) Space Configurator, as I understand it, is a C + + STL memory management component (including memory application and release); Of course, not only memory, but also to the hard disk to request space; I mainly look at the configuration and release of memory ("Configuration" should be "application" meaning). STL's philosophy of this design mainly includes the following four aspects: 1, to the system heap space to apply for memory space 2, consider the application of multi-threading; 3, consider the contingency measures of insufficient memory; 4, consider the problem of excessive "small chunks" of memory fragmentation; The basic actions of C + + applications are:: operator new (), the basic action of releasing memory is:: Operatordelete (). Furthermore, the new and delete operators in the STL are equivalent to the malloc () and free () functions to complete the application and release of memory; (http://www.cppblog.com/michaelgao/archive/2008/06/05/ 52248.html illustrates the implementation of C++NEW, its practical is the malloc function) STL designed a two-tier Configurator: 1. First Level configurator: direct use of malloc and New (); 2. When the configuration area is more than 128bytes, the first level configurator is used, and when the configuration area is less than 128bytes, the concept of "memory pool" is used to perform the actual memory configuration, release, and ReAlloc () in the first level configurator with malloc (), free (), and C functions.   Reconfiguration operations, and implements a mechanism similar to C + + new handler.   The so-called C + + new handler mechanism, you can ask the system to call a function that you specify when the memory configuration needs are not met. The allocate () and Relloc () functions of the SGI first level configurator are all called after the malloc () and realloc () functions are unsuccessful, calling the Oom_malloc () and Oom_relloc () functions, both of which have internal loops, which are constantly called " Insufficient memory processing routines ", expecting to get enough memory to complete a task after a call. However, if the "Memory processing routines" are not set by the guest, The Oom_malloc () and Oom_relloc () functions throw bad_alloc exceptions or terminate the program with exit (1); The configuration policy of the SGI second-level configurator: If the area is large enough, More than 128Bytes, it is transferred to the first Level configurator processing; When the region is less than 128Bytes, the memory pool management; memory pool management policy: Proactively raise any small area block of memory demand to a multiple of 8, the respective management 8,16,24,32 ... Total 128BytesThe regional nodes of the 16 Freelists.free lists are structured as follows: union{Union obj * FREE_LIST_LINK; Char Client_data[1]}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"STL Source Analysis" Space Configurator

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.