程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 模仿STL標准庫寫了一個內存池

模仿STL標准庫寫了一個內存池

編輯:C++入門知識

   _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 +                }
 
 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved