source: proiecte/swift/trunk/lib/hoard-371/src/heaplayers/experimental/lazyheap.h @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 674 bytes
Line 
1// -*- C++ -*-
2
3#ifndef _LAZYHEAP_H_
4#define _LAZYHEAP_H_
5
6template <class SuperHeap>
7class LazyHeap {
8public:
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
32private:
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
Note: See TracBrowser for help on using the repository browser.