Changeset 280


Ignore:
Timestamp:
Dec 10, 2002, 7:42:47 PM (18 years ago)
Author:
pooh
Message:
Location:
to-imperative/trunk/libp++
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/libp++/pxx_chunk_allocator.cc

    r276 r280  
    2323#include "pxx_chunk_allocator.ih"
    2424
    25 // This file is for error checking only
     25namespace pxx
     26{
     27
     28size_t chunks_in_block = 1024 ;
     29
     30}
  • to-imperative/trunk/libp++/pxx_chunk_allocator.hh

    r276 r280  
    3232extern size_t chunks_in_block ;
    3333
     34//
     35// Memory block header structure
     36struct BlockHeader
     37{
     38  //
     39  // Reference counter that is equal to a number of allocated chunks in a
     40  // block
     41  uintptr_t ref_count ;
     42  //
     43  // Pointer to the previous free block
     44  BlockHeader* prev ;
     45  //
     46  // Pointer to the next free block
     47  BlockHeader* next ;
     48  //
     49  //
     50  BlockHeader* left ;
     51  //
     52  //
     53  BlockHeader* right ;
     54  //
     55  //
     56  int balance ;
     57  //
     58  // Constructor
     59  BlockHeader (BlockHeader* _prev, BlockHeader* _next) ;
     60
     61  NO_COPY_CTOR(BlockHeader)
     62  NO_ASSIGN(BlockHeader)
     63  //
     64  // Remove a memory block from block list
     65  inline void remove () ;
     66
     67};
     68
    3469template <typename type_t>
    3570class ChunkAllocator
     
    3873private:
    3974
     75  struct FreeList
     76  {
     77    //
     78    // Pointer to the previous item
     79    FreeList* prev ;
     80    //
     81    // Pointer to the next item
     82    FreeList* next ;
     83    //
     84    //
     85    // Remove item from the list
     86    inline void remove () ;
     87
     88  };
     89
     90
    4091  Allocator& block_allocator ;
    4192
    42   void* block_list ;
     93  BlockHeader block_list ;
    4394
    44   type_t* free_list ;
     95  FreeList free_list ;
    4596
    4697  size_t chunk_size ;
     
    50101  size_t nchunks ;
    51102
     103  BlockHeader* root ;
     104
    52105public:
    53106  //
    54107  // Constructor
    55108  inline ChunkAllocator (Allocator& _allocator = default_allocator) ;
     109  //
     110  // Constructor with explicit number of chunks in block
     111  inline ChunkAllocator (
     112    size_t _nchunks,
     113    Allocator& _allocator = default_allocator
     114  ) ;
    56115  //
    57116  // Destructor
     
    61120  inline type_t* allocate () ;
    62121
    63   inline void deallocate (void* _ptr)
    64   {
    65     *(void**)_ptr = free_list;
    66     free_list = _ptr;
    67   }
     122  inline void deallocate (type_t* _ptr) ;
    68123
    69124private:
    70125
    71   inline void init_block (void* _ptr) ;
     126  inline BlockHeader* get_block (void* _ptr) ;
     127  inline void init_block (BlockHeader* _ptr) ;
    72128
    73129};
Note: See TracChangeset for help on using the changeset viewer.