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

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 1.2 KB
Line 
1/* -*- C++ -*- */
2
3#ifndef _HYBRIDHEAP_H_
4#define _HYBRIDHEAP_H_
5
6#include <assert.h>
7#include "sassert.h"
8#include "hldefines.h"
9
10/**
11 * @class HybridHeap
12 * Objects no bigger than BigSize are allocated and freed to SmallHeap.
13 * Bigger objects are passed on to the super heap.
14 */
15
16namespace HL {
17
18template <int BigSize, class SmallHeap, class BigHeap>
19class HybridHeap : public SmallHeap {
20public:
21
22  HybridHeap (void)
23  {
24  }
25
26  enum { Alignment = ((int) SmallHeap::Alignment < (int) BigHeap::Alignment) ?
27                      (int) SmallHeap::Alignment :
28                      (int) BigHeap::Alignment };
29
30  MALLOC_FUNCTION INLINE void * malloc (size_t sz) {
31    if (sz <= BigSize) {
32      return SmallHeap::malloc (sz);
33    } else {
34      return slowPath (sz);
35    }
36  }
37 
38  inline void free (void * ptr) {
39    if (SmallHeap::getSize(ptr) <= BigSize) {
40      SmallHeap::free (ptr);
41    } else {
42      bm.free (ptr);
43    }
44  }
45 
46  inline void clear (void) {
47    bm.clear();
48    SmallHeap::clear();
49  }
50 
51
52private:
53
54  MALLOC_FUNCTION NO_INLINE
55    void * slowPath (size_t sz) {
56    return bm.malloc (sz);
57  }
58
59
60  HL::sassert<(BigSize > 0)> checkBigSizeNonZero;
61
62  BigHeap bm;
63};
64
65}
66
67#endif
Note: See TracBrowser for help on using the repository browser.