| 1 |
// -*- C++ -*- |
| 2 |
|
| 3 |
/* |
| 4 |
|
| 5 |
Heap Layers: An Extensible Memory Allocation Infrastructure |
| 6 |
|
| 7 |
Copyright (C) 2000-2020 by Emery Berger |
| 8 |
http://www.emeryberger.com |
| 9 |
[email protected] |
| 10 |
|
| 11 |
Heap Layers is distributed under the terms of the Apache 2.0 license. |
| 12 |
|
| 13 |
You may obtain a copy of the License at |
| 14 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
|
| 16 |
*/ |
| 17 |
|
| 18 |
|
| 19 |
#ifndef HL_ONEHEAP_H |
| 20 |
#define HL_ONEHEAP_H |
| 21 |
|
| 22 |
// |
| 23 |
// Wrap a single instance of a heap. |
| 24 |
// |
| 25 |
|
| 26 |
namespace HL { |
| 27 |
|
| 28 |
template <class SuperHeap> |
| 29 |
class OneHeap { |
| 30 |
public: |
| 31 |
OneHeap (void) |
| 32 |
: theHeap (getHeap()) |
| 33 |
{} |
| 34 |
|
| 35 |
inline void * malloc (const size_t sz) { |
| 36 |
return theHeap->malloc (sz); |
| 37 |
} |
| 38 |
inline void free (void * ptr) { |
| 39 |
theHeap->free (ptr); |
| 40 |
} |
| 41 |
inline int remove (void * ptr) { |
| 42 |
return theHeap->remove (ptr); |
| 43 |
} |
| 44 |
inline void clear (void) { |
| 45 |
theHeap->clear(); |
| 46 |
} |
| 47 |
inline size_t getSize (void * ptr) { |
| 48 |
return theHeap->getSize (ptr); |
| 49 |
} |
| 50 |
|
| 51 |
enum { Alignment = SuperHeap::Alignment }; |
| 52 |
|
| 53 |
private: |
| 54 |
|
| 55 |
SuperHeap * theHeap; |
| 56 |
|
| 57 |
inline static SuperHeap * getHeap (void) { |
| 58 |
static SuperHeap theHeap; |
| 59 |
return &theHeap; |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
#endif |