Changeset 276


Ignore:
Timestamp:
Dec 9, 2002, 9:29:34 PM (18 years ago)
Author:
pooh
Message:
  • Code cleanup.
Location:
to-imperative/trunk/libp++
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/libp++/Makefile

    r271 r276  
    77
    88PXX_MODULES = \
     9  pxx_common \
    910  pxx_sys_error \
    1011  pxx_malloc_allocator \
    1112  pxx_heap \
    1213  pxx_heap_allocator \
    13   pxx_common
     14  pxx_default_allocator \
     15  pxx_chunk_allocator
    1416
    1517PXX_AHEADERS = $(PXX_AMODULES:=.hh)
  • to-imperative/trunk/libp++/pxx_chunk_allocator.cc

    r103 r276  
    11//
    2 // Copyright (C) 2000, 2001 Andrey Slepuhin <pooh@msu.ru>
     2// Copyright (C) 2000-2002 Andrey Slepuhin <pooh@msu.ru>
    33//
    44// libp++ is free software; you can redistribute it and/or modify
     
    2121// Author: Andrey Slepuhin <pooh@msu.ru>
    2222
    23 #include "pxx_chunk_allocator.hh"
     23#include "pxx_chunk_allocator.ih"
    2424
    2525// This file is for error checking only
  • to-imperative/trunk/libp++/pxx_chunk_allocator.hh

    r103 r276  
    11//
    2 // Copyright (C) 2000, 2001 Andrey Slepuhin <pooh@msu.ru>
     2// Copyright (C) 2000-2002 Andrey Slepuhin <pooh@msu.ru>
    33//
    44// libp++ is free software; you can redistribute it and/or modify
     
    2424#define __pxx_chunk_allocator_hh__
    2525
    26 #include "pxx_i_chunk_allocator.hh"
    27 #include "pxx_i_allocator.hh"
     26#include "pxx_allocator.hh"
     27#include "pxx_default_allocator.hh"
    2828
    2929namespace pxx
    3030{
    3131
    32 class ChunkAllocator :
    33   public I_ChunkAllocator
     32extern size_t chunks_in_block ;
     33
     34template <typename type_t>
     35class ChunkAllocator
    3436{
    3537
    3638private:
    3739
    38   I_Allocator& block_allocator ;
     40  Allocator& block_allocator ;
    3941
    4042  void* block_list ;
    4143
    42   void* free_list ;
     44  type_t* free_list ;
    4345
    4446  size_t chunk_size ;
     
    4648  size_t block_size ;
    4749
     50  size_t nchunks ;
     51
    4852public:
    49 
    50   inline ChunkAllocator (I_Allocator& _allocator, size_t const _chunksize) :
    51     block_allocator (_allocator),
    52     block_list (0),
    53     free_list (0),
    54     chunk_size (get_chunk_size(_chunksize)),
    55     block_size (
    56       size_align(256 * chunk_size, page_size) - sizeof(uintptr_t)
    57     )
    58   {}
    59 
    60   inline ~ChunkAllocator ()
    61   {
    62     void* p = block_list;
    63     while (p != 0) {
    64       void* q = p;
    65       p = *(void**)p;
    66       block_allocator.deallocate(q);
    67     }
    68   }
    69 
    70   inline void* allocate ()
    71   {
    72     if (free_list != 0) {
    73       void* p = free_list;
    74       free_list = *(void**)free_list;
    75       return p;
    76     } else {
    77       void* p = block_allocator.allocate(block_size);
    78       init_block(p);
    79       return ChunkAllocator::allocate();
    80     }
    81   }
     53  //
     54  // Constructor
     55  inline ChunkAllocator (Allocator& _allocator = default_allocator) ;
     56  //
     57  // Destructor
     58  inline ~ChunkAllocator () ;
     59  //
     60  // Allocate one chunk
     61  inline type_t* allocate () ;
    8262
    8363  inline void deallocate (void* _ptr)
     
    8969private:
    9070
    91   static inline size_t get_chunk_size (size_t const _size)
    92   {
    93     return size_align(_size, sizeof(void*));
    94   }
    95 
    96   inline void init_block (void* _ptr)
    97   {
    98     *(void**)_ptr = block_list;
    99     block_list = _ptr;
    100     void* p = _ptr;
    101     void* q = (char*)p + block_size - chunk_size;
    102     while (p <= q) {
    103       p = *(void**)p = (char*)p + chunk_size;
    104     }
    105     p = (char*)p - chunk_size;
    106     *(void**)p = free_list;
    107     free_list = _ptr;
    108   }
     71  inline void init_block (void* _ptr) ;
    10972
    11073};
  • to-imperative/trunk/libp++/pxx_malloc_allocator.ih

    r275 r276  
    6868inline size_t MallocAllocator::get_real_size (size_t _size)
    6969{
    70   return size;
     70  return _size;
    7171}
    7272
Note: See TracChangeset for help on using the changeset viewer.