Changeset 277


Ignore:
Timestamp:
Dec 10, 2002, 3:11:54 PM (18 years ago)
Author:
pooh
Message:
  • Added get_block() methods.
Location:
to-imperative/trunk/libp++
Files:
7 edited

Legend:

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

    r275 r277  
    6060  // of memory block to be allocated
    6161  virtual size_t get_real_size (size_t _size) = 0 ;
     62  //
     63  // Returns (if possible) the start address of allocated block containing a
     64  // pointer, otherwise returns null
     65  virtual void* get_block (void* _ptr) = 0 ;
     66  //
     67  // The same as previous, but using block size
     68  virtual void* get_block (void* _ptr, size_t _size) = 0 ;
    6269
    6370};
  • to-imperative/trunk/libp++/pxx_default_allocator.hh

    r275 r277  
    7474  // of memory block to be allocated
    7575  inline size_t get_real_size (size_t _size) ;
     76  //
     77  // Returns (if possible) the start address of allocated block containing a
     78  // pointer, otherwise returns null
     79  inline void* get_block (void* _ptr) ;
     80  //
     81  // The same as previous, but using block size
     82  inline void* get_block (void* _ptr, size_t _size) ;
    7683
    7784};
  • to-imperative/trunk/libp++/pxx_default_allocator.ih

    r275 r277  
    6666}
    6767
     68//
     69// Returns (if possible) the start address of allocated block containing a
     70// pointer, otherwise returns null
     71inline void* DefaultAllocator::get_block (void* _ptr)
     72{
     73  if (allocator == null) set(default_malloc_allocator);
     74  return allocator->get_block(_ptr);
     75}
     76
     77//
     78// The same as previous, but using block size
     79inline void* DefaultAllocator::get_block (void* _ptr, size_t _size)
     80{
     81  if (allocator == null) set(default_malloc_allocator);
     82  return allocator->get_block(_ptr, _size);
     83}
     84
    6885inline Allocator& DefaultAllocator::get ()
    6986{
  • to-imperative/trunk/libp++/pxx_heap_allocator.hh

    r275 r277  
    129129  inline size_t get_size (void* _ptr) ;
    130130  //
     131  // Returns (if possible) the start address of allocated block containing a
     132  // pointer, otherwise returns null
     133  inline void* get_block (void* _ptr) ;
     134  //
     135  // The same as previous, but using block size
     136  inline void* get_block (void* _ptr, size_t _size) ;
     137  //
    131138  // Dump memory map
    132139  void memory_dump () ;
  • to-imperative/trunk/libp++/pxx_heap_allocator.ih

    r275 r277  
    9595}
    9696
     97//
     98// Returns (if possible) the start address of allocated block containing a
     99// pointer, otherwise returns null
     100inline void* HeapAllocator::get_block (void* _ptr)
     101{
     102  size_t s = current_size;
     103  while (s >= min_free_size) {
     104    void* p =
     105      ptr_add_offset(start_addr, ptr_sub(_ptr, start_addr) & (~(s - 1)));
     106    if (((BlockHeader*)p)->size == (s | 0x01))
     107      return ptr_add_offset(p, sizeof(uintptr_t));
     108    s >>= 1;
     109  }
     110  return null;
     111}
     112
     113//
     114// The same as previous, but using block size
     115inline void* HeapAllocator::get_block (void* _ptr, size_t _size)
     116{
     117  _size += sizeof(uintptr_t);
     118  if (_size < min_free_size) _size = min_free_size ;
     119  _size = exps_of_two[get_order(_size)];
     120  void* real_block =
     121    ptr_add_offset(start_addr, ptr_sub(_ptr, start_addr) & (~(_size - 1)));
     122  return ptr_add_offset(real_block, sizeof(uintptr_t));
     123}
     124
    97125}
    98126
  • to-imperative/trunk/libp++/pxx_malloc_allocator.hh

    r275 r277  
    5959  // of memory block to be allocated
    6060  inline size_t get_real_size (size_t _size) ;
     61  //
     62  // Returns (if possible) the start address of allocated block containing a
     63  // pointer, otherwise returns null
     64  inline void* get_block (void* _ptr) ;
     65  //
     66  // The same as previous, but using block size
     67  inline void* get_block (void* _ptr, size_t _size) ;
    6168};
    6269
  • to-imperative/trunk/libp++/pxx_malloc_allocator.ih

    r276 r277  
    7171}
    7272
     73//
     74// Returns (if possible) the start address of allocated block containing a
     75// pointer, otherwise returns null
     76inline void* MallocAllocator::get_block (void*)
     77{
     78  return null;
     79}
     80
     81//
     82// The same as previous, but using block size
     83inline void* MallocAllocator::get_block (void*, size_t)
     84{
     85  return null;
     86}
     87
    7388}
    7489
Note: See TracChangeset for help on using the changeset viewer.