Changeset 282


Ignore:
Timestamp:
Dec 10, 2002, 8:11:14 PM (18 years ago)
Author:
pooh
Message:
  • Use allocator features.
Location:
to-imperative/trunk/libp++
Files:
2 edited

Legend:

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

    r280 r282  
    8989
    9090
    91   Allocator& block_allocator ;
     91  Allocator& allocator ;
    9292
    9393  BlockHeader block_list ;
  • to-imperative/trunk/libp++/pxx_chunk_allocator.ih

    r280 r282  
    5757  Allocator& _allocator /* = default_allocator */
    5858) :
    59   block_allocator (_allocator),
     59  allocator (_allocator),
    6060  block_list (&block_list, &block_list),
    6161  chunk_size (size_align(sizeof(type_t), 2 * sizeof(void*))),
     
    7575  Allocator& _allocator /* = default_allocator */
    7676) :
    77   block_allocator (_allocator),
     77  allocator (_allocator),
    7878  block_list (&block_list, &block_list),
    7979  chunk_size (size_align(sizeof(type_t), 2 * sizeof(void*))),
     
    8484    _allocator.get_real_size(_nchunks * chunk_size + sizeof(BlockHeader));
    8585printf("block_size: %u\n", block_size);
     86printf("features: %08x\n", allocator.get_features());
    8687  nchunks = (block_size - sizeof(BlockHeader))/chunk_size;
    8788}
     
    9495    void* q = p;
    9596    p = p->next;
    96     block_allocator.deallocate(q);
     97    allocator.deallocate(q);
    9798  }
    9899}
     
    108109    return (type_t*)p;
    109110  } else {
    110     BlockHeader* p = (BlockHeader*)block_allocator.allocate(block_size);
     111    BlockHeader* p = (BlockHeader*)allocator.allocate(block_size);
    111112//printf("Allocated block at %p\n", p);
    112113    init_block(p);
     
    213214//printf("Deallocating block at %p\n", b);
    214215    b->remove();
    215     root = node_remove(root, b);
    216     block_allocator.deallocate(b);
     216    if ((allocator.get_features() & ALLOCATOR_HAS_GET_BLOCK_WITH_SIZE) == 0) {
     217      root = node_remove(root, b);
     218    }
     219    allocator.deallocate(b);
    217220  }
    218221}
     
    221224inline BlockHeader* ChunkAllocator<type_t>::get_block (void* _ptr)
    222225{
    223   void* p = block_allocator.get_block(_ptr, block_size);
    224   if (p != null) return (BlockHeader*)p;
    225   else {
     226  if ((allocator.get_features() & ALLOCATOR_HAS_GET_BLOCK_WITH_SIZE) != 0) {
     227    return (BlockHeader*)(allocator.get_block(_ptr, block_size));
     228  } else {
    226229    BlockHeader* node = root;
    227230    do {
     
    370373  p->next = &free_list;
    371374  free_list.prev = p;
    372   {
     375  if ((allocator.get_features() & ALLOCATOR_HAS_GET_BLOCK_WITH_SIZE) == 0) {
    373376    _ptr->left = _ptr->right = null;
    374377    _ptr->balance = 0;
Note: See TracChangeset for help on using the changeset viewer.