Imitating the STL standard library, write a memory pool

Source: Internet
Author: User

   _DEFAULT_ALLOC_H_  #include <> #include <stdlib.h> #include <iostream>                                    *           *oom_realloc( *          (*                *               *p =              (NULL ==                 p =                         deallocate( *              *reallocate( *               *p =              (NULL ==                 p =                       typedef  (*                       handler old_handler =             _malloc_alloc_oom_handler =                   };      (*malloc_alloc::_malloc_alloc_oom_handler)() =       *          (*          *                       my_malloc_handle =              res =              (_malloc_alloc_oom_handler ==                  std::cerr<<<<std::endl, exit(-                                      *malloc_alloc::oom_realloc( *          (*          *                       my_malloc_handle =              res =              (_malloc_alloc_oom_handler ==                  std::cerr <<  << std::endl, exit(-                                       {_ALIGN =       {_MAX_BYTES =       {_FREE_LIST_NUM = _MAX_BYTES /                                     union obj *              *                         obj *                     *                    *                                          (bytes + _ALIGN - ) & ~(_ALIGN -                                   round_up(bytes) / _ALIGN -                      *                             *chunk_alloc(size_t size,  &                *           deallocate( *           *reallocate( *     };       * default_alloc::free_start =       * default_alloc::free_end =      size_t default_alloc::heap_size =      default_alloc::obj *  default_alloc::free_list[_FREE_LIST_NUM] =     { , , , , , , , , , , , , , , ,      , , , , , , , , , , , , , , ,        *          obj *         obj **          (n >                       list_temp = free_list +          ( == *               *r = (obj *                       res = *         *list_temp = res->                default_alloc::deallocate( *          obj **list_temp = free_list +         obj *res = (obj *         res->next = *         *list_temp =       *default_alloc::reallocate( *                       *           objs =           *chunks =         obj **list_temp = free_list +         obj *res = (obj *         obj *next_obj = *list_temp = (obj *)(chunks +          ( i = ; ; ++               (i == objs -                   next_obj->next =                                next_obj->next = next_obj +             next_obj = next_obj->                           *default_alloc::chunk_alloc(size_t size,  &           *         size_t total_bytes = size *         size_t bytes_left = free_end -           (bytes_left >=              res =             free_start +=                         (bytes_left >=              nobjs = bytes_left /             res =             free_start += nobjs *                                     size_t bytes_to_get =  * total_bytes + round_up(heap_size >>               (bytes_left >                   obj **list_temp = free_list +                 ((obj *)(free_start))->next = *                 *list_temp = (obj *              free_start = ( *              ( ==                  obj **                  ( i = size; i <= _MAX_BYTES; i +=                      list_temp = free_list +                      ( != *                          free_start = ( *)*                         *list_temp = (*list_temp)->                         free_end = free_start +                                            free_end =                  free_start = ( *              heap_size +=             free_end = free_start +                }  

 

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.