"Fossies" - the Fresh Open Source Software Archive

Member "heaplayers-351/heaplayers/experimental/lazyheap.h" (3 May 2006, 674 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 "lazyheap.h" see the Fossies "Dox" file reference documentation.

    1 // -*- C++ -*-
    2 
    3 #ifndef _LAZYHEAP_H_
    4 #define _LAZYHEAP_H_
    5 
    6 template <class SuperHeap>
    7 class LazyHeap {
    8 public:
    9 
   10   LazyHeap (void)
   11     : initialized (0)
   12   {}
   13 
   14   ~LazyHeap (void) {
   15     if (initialized) {
   16       delete lazyheap;
   17     }
   18   }
   19 
   20   inline void * malloc (size_t sz) {
   21     return getHeap()->malloc (sz);
   22   }
   23   inline void free (void * ptr) {
   24     getHeap()->free (ptr);
   25   }
   26   inline void clear (void) {
   27     if (initialized) {
   28       getHeap()->clear();
   29     }
   30   }
   31 
   32 private:
   33 
   34   SuperHeap * getHeap (void) {
   35     if (!initialized) {
   36       lazyheap = new SuperHeap;
   37       initialized = 1;
   38     }
   39     return lazyheap;
   40   }
   41 
   42   bool initialized;
   43   SuperHeap * lazyheap;
   44 };
   45 
   46 
   47 #endif