"Fossies" - the Fresh Open Source Software Archive

Member "heaplayers-351/allocators/vam/reapbase.h" (15 Nov 2005, 1053 Bytes) of package /linux/misc/old/heaplayers_3_5_1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "reapbase.h" see the Fossies "Dox" file reference documentation.

    1 // -*- C++ -*-
    2 
    3 #ifndef _REAPBASE_H_
    4 #define _REAPBASE_H_
    5 
    6 #include "vamcommon.h"
    7 
    8 namespace VAM {
    9 
   10 // ReapBase: base of reaps that allocate objects of a fixed size by pointer bumping
   11 class ReapBase {
   12 
   13 public:
   14 
   15     inline void * malloc() {
   16         void * ptr = NULL;
   17         if (_num_bumped < _num_total) {
   18             ptr = reinterpret_cast<void *>(_bump_ptr);
   19             _bump_ptr += _object_size;
   20             _num_bumped++;
   21             _num_free--;
   22         }
   23         return ptr;
   24     }
   25 
   26     inline size_t getObjectSize() {
   27         return _object_size;
   28     }
   29 
   30     inline size_t getNumTotal() {
   31         return _num_total;
   32     }
   33 
   34     inline size_t getNumFree() {
   35         return _num_free;
   36     }
   37 
   38 protected:
   39 
   40     size_t _object_size;
   41     size_t _num_total;
   42     size_t _num_free;
   43     size_t _base_ptr;
   44 
   45     inline void initReapBase(size_t object_size, size_t num_total, size_t num_free, size_t base_ptr) {
   46         _object_size = object_size;
   47         _num_total = num_total;
   48         _num_free = num_free;
   49         _base_ptr = base_ptr;
   50 
   51         _num_bumped = 0;
   52         _bump_ptr = base_ptr;
   53     }
   54 
   55 private:
   56     size_t _num_bumped;
   57     size_t _bump_ptr;
   58 
   59 };  // end of class ReapBase
   60 
   61 };  // end of namespace VAM
   62 
   63 #endif