Changeset 272


Ignore:
Timestamp:
Dec 9, 2002, 5:49:31 PM (18 years ago)
Author:
pooh
Message:
  • More minor cleanups.
File:
1 edited

Legend:

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

    r271 r272  
    4545  for (unsigned i = 0; i < sizeof(size_t) * 8; i++)
    4646    lists[i].size = exps_of_two[i];
    47   BlockHeader* p = reinterpret_cast<BlockHeader*>(start_addr);
     47  BlockHeader* p = static_cast<BlockHeader*>(start_addr);
    4848  (lists + get_order(current_size))->put(p);
    4949}
     
    105105void HeapAllocator::deallocate (void* _ptr)
    106106{
     107  BlockHeader* start = static_cast<BlockHeader*>(start_addr);
    107108  //
    108109  // Shift a pointer to a real start of memory block
     
    113114  //
    114115  // Loop and glue adjacent free blocks
    115   while (size < current_size) {
     116  for (; size < current_size; size <<= 1) {
    116117    //
    117118    // Get a pointer to appropriate adjacent block
    118     BlockHeader* q =
    119       (BlockHeader*)ptr_add_offset(start_addr, (ptr_sub(p, start_addr) ^ size));
    120     //
    121     // If it is free...
    122     if (q->size == size) {
    123       //
    124       // ...delete it from list
    125       q->remove();
    126       //
    127       // Obtain a pointer to combined free block
    128       p = (BlockHeader*)ptr_add_offset(start_addr,
    129         ptr_sub(p, start_addr) & ptr_sub(q, start_addr));
    130       //
    131       // Advance a size
    132       size <<= 1;
    133     }
    134     //
    135     // If it is allocated...
    136     else break;
     119    BlockHeader* q = ptr_add_offset(start, (ptr_sub(p, start) ^ size));
     120    //
     121    // If it is allocated or has wrong size
     122    if (size != q->size) break;
     123    //
     124    // Delete a block from free block list
     125    q->remove();
     126    //
     127    // Obtain a pointer to combined free block
     128    p = ptr_add_offset(start, ptr_sub(p, start) & ptr_sub(q, start));
    137129  }
    138130  //
Note: See TracChangeset for help on using the changeset viewer.