source: proiecte/swift/trunk/lib/hoard-371/src/heaplayers/bins4k.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.4 KB
Line 
1// -*- C++ -*-
2
3#if !defined(_BINS4K_H_)
4#define _BINS4K_H_
5
6#include "bins.h"
7#include "sassert.h"
8
9namespace HL {
10
11  template <class Header>
12    class bins<Header, 4096> { 
13
14    public:
15      bins (void) {}
16
17      enum { NUM_BINS = 33 };
18      enum { BIG_OBJECT = 4096 - sizeof(Header) };
19
20      static const size_t _bins[NUM_BINS];
21
22      static inline int getSizeClass (size_t sz) {
23        assert (sz <= BIG_OBJECT);
24        if (sz < 8) {
25          return 0;
26        } else if (sz <= 128) {
27          return ((sz + 7) >> 3) - 1;
28        } else {
29          return slowLookupSizeClass (sz);
30        }
31      }
32
33      static inline size_t getClassSize (const int i) {
34        assert (i >= 0);
35        assert (i < NUM_BINS);
36        return _bins[i];
37      }
38
39    private:
40     
41      static int slowLookupSizeClass (const size_t sz) {
42        // Find the size class for a given object size
43        // (the smallest i such that _bins[i] >= sz).
44        int sizeclass = 0;
45        while (_bins[sizeclass] < sz) 
46          {
47            sizeclass++;
48            assert (sizeclass < NUM_BINS);
49          }
50        return sizeclass;
51      }
52     
53      sassert<(BIG_OBJECT > 0)> verifyHeaderSize;
54     
55    };
56}
57
58template <class Header>
59const size_t HL::bins<Header, 4096>::_bins[NUM_BINS] = {8UL, 16UL, 24UL, 32UL, 40UL, 48UL, 56UL, 64UL, 72UL, 80UL, 88UL, 96UL, 104UL, 112UL, 120UL, 128UL, 152UL, 176UL, 208UL, 248UL, 296UL, 352UL, 416UL, 496UL, 592UL, 704UL, 856UL, 1024UL, 1224UL, 1712UL, 2048UL, 3416UL, 4096UL - sizeof(Header)};
60
61#endif
62
Note: See TracBrowser for help on using the repository browser.