SGI-STL abbreviated (a) - memory allocator resolve

defalloc.h: 
    Default distributor allocator: 
        early dedicated to the HP default distributor is currently not in favor of use; 
        only a simple allocator template package, re-statement (or type outside throwing) the necessary type Type, in addition to provide and freeing memory interface (bottom layer using the global :: operator new and :: operator Delete memory allocation and release); 
        ; taking the address references, often take the address of the interface reference constant 
        allocate: new hop fail to cancel internal memory applications but direct transfer throws an exception handler; 
        init_page_size: the maximum size of the application page size, using 4K ( 4096 ) / the sizeof (T) is calculated; 
        MAX_SIZE: the maximum size of the application, using UINT_MAX / the sizeof (T) is calculated. 
        Further template specialization the allocator < void > , weighing only declare a pointer type; 
        
stl_alloc.h: 
    inside STL allocator the allocator (default template class __default_alloc_template threading safe dispenser):
        With the default allocator redeclarations some necessary type Type, application and release memory interface, taking the address references, constant address taken often cited, max_size: applying the maximum size of the space, use size_t ( - 
    underlying memory processing template class __default_alloc_template (Presumably, the memory pool as a template class):. 1 ) / the sizeof (T) is calculated; 
        differs in that the underlying memory process used is a the alloc (actually __default_alloc_template template class or malloc_alloc (__ malloc_alloc_template)), apply through it and release memory; 
        Providing a default constructor, destructor , assignment configuration, configured construct (by " placing " new new ), destruction destroy (by calling its destructor), providing rebind the class structure declaration; 
        furthermore template specialization the allocator < void > , redeclarations some necessary type of the type; 
    the STL inside the dispensing adapter __allocator (provided by the underlying template parameter memory allocation): 
        as above by, but with memory type object underlying __underlying_alloc a template parameter supplied; when __allocator <_TP, the alloc> and when the allocator <_Tp> the same; 
        template parameter, respectively threads BOOL, int inst, threads is true, compared with thread-safe, or only for single-threaded case; inst just a logo, to support a number of different __default_alloc_template instance; 
        _ALIGN: byte alignment 8 bytes; 
        _MAX_BYTES: maximum byte 128 bytes, malloc_alloc distribution over the call; 
        _NFREELISTS: pointer list after the release _S_free_list size 128 / . 8 = 16 ; 
        _S_free_list: list after the release of the array, each pointing to save list pointer index address space; 
        _S_start_free ( 0 ), _ S_end_free ( 0 ), _ S_heap_size ( 0 ): the allocation status block; 
        _S_node_allocator_lock: a dispenser lock object; 
        internal automatic locks _Lock; _S_node_allocator_lock packaging for locking and unlocking, the windows using atomic lock used for other platforms reference count plus the pthread_mutex_lock; 
        _OBJ: the joint, a package list pointer or a linked list of objects, in order to save space to space applications to as point to the next node memory; 
        for external call interface allocate memory allocation, freeing memory DEALLOCATE, Reallocate reapply memory; 
        _S_round_up: byte alignment, adjusted to _ALIGN integer number of bytes (n + (size_t) _ALIGN- . 1 ) & ~ ((size_t) _ALIGN - . 1 )); 
        _S_freelist_index: calculating a current position in the index byte size _S_free_list application list (n- + (size_t) _ALIGN- . 1 ) / (size_t) _ALIGN - . 1 , the range of 0 to 15 ; 
        therefore, the list of saved results _S_free_list layout application such as: [ 8 , 16 , 24 , 32 , 40 , 48 , 56 , 64 , ..., 128 ], each as a single linked list node list, the node application and release date it is the header, 
        so that expedite the application and release operations, in fact the released node header loaded directly linked list of nodes is not free, if the list is empty space of the memory size of the application corresponding index; 
        _S_refill, _S_chunk_alloc: filler node list application memory space and a lower (in fact _S_chunk_alloc internal space is not at the beginning of the application corresponding to the application space, but the corresponding application layout index
        More times bytes (to avoid memory fragmentation and frequent re-apply) (the specific operational details can look at the source code to achieve), _ S_refill list layout application after the application has not been responsible for filling _S_chunk_alloc used to split the corresponding 
        the next node list for reference is supplied directly without having to use the application for memory, then returns an upper memory for use);
    malloc_alloc large memory allocation inside __default_alloc_template class template class used (ie __malloc_alloc_template < 0 > template class): 
        __malloc_alloc_template provide external use interfaces: 
            the allocate: internal application calls malloc memory, if fails, call _S_oom_malloc; 
            DEALLOCATE: internal direct call free release memory; 
            Reallocate: internal call for memory realloc weight, if fails, the call _S_oom_realloc; 
            also provides a set __set_malloc_handler application handler; 
            _S_oom_malloc: internal application determined by the handler is empty, if the throw is empty the bad_alloc exception, otherwise processing function calls to malloc and the cycle continues until the application is successful; before each application will 
            call the handler; 
            _S_oom_realloc: _S_oom_malloc the same type, the cycle call realloc re-apply; 
            
    dependencies: distributor __allocator, allocator -> distributor template __default_alloc_template (core components) -> __ malloc_alloc_template (large memory application process) (or global malloc, as Free -> 
              Global malloc, as Free ; 
              
    __allocator, allocator, __ default_alloc_template have a large application management, small memory mechanism (the bottom by calling malloc / as Free / remalloc achieve) and lock resource protection (of course you can also use the macro setting is not locked, 
    at this time if the upper securing their own resources, whether to lock some of your resources protection, depending on the specific ), the other directly call the malloc / Free / remalloc implemented; 
            
    other adapter memory allocation template class: 
        simple_alloc simple dispenser package, before allocating memory debug_alloc with extra 8 bytes of debug information package dispenser, _Alloc_traits extraction template class type dispenser ; 
        wherein _Alloc_traits template parameter dispenser may be specialized version type, such as: allocator, __ allocator, __ malloc_alloc_template , __ default_alloc_template, debug_alloc; 
        in addition dispenser _Alloc_traits template parameters _S_instanceless above type is true, the other user-defined types are is false, when obtained by the rebind allocator_type is true, 
        the other is acquired by a corresponding dispenser allocator_type also offers a simple simple_alloc _Alloc_type type dispenser package; 
        _Alloc_traits in every corner of the container with the template class, and by default the container allocation Is the allocator <T>Or alloc (__ default_alloc_template or malloc_alloc (__ malloc_alloc_template)); 
        single_client_alloc the dispenser when __default_alloc_template unlocked quickly but unsafe, malloc_alloc security but not fast enough, allocator is the default dispenser security more efficient;
    

 

Guess you like

Origin www.cnblogs.com/haomiao/p/11647200.html