Debian Codegraph @

vendor/Heap-Layers/heaps/combining/tryheap.h

raw symbols SCIP
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 #ifndef HL_TRYHEAP_H
19 #define HL_TRYHEAP_H
20
21 #include <cstddef>
22
23 namespace HL {
24
25 template <class Heap1, class Heap2>
26 class TryHeap : public Heap2 {
27 public:
28
29 TryHeap (void)
30 {}
31
32 inline void * malloc (size_t sz) {
33 void * ptr = heap1.malloc (sz);
34 if (ptr == NULL)
35 ptr = Heap2::malloc (sz);
36 return ptr;
37 }
38
39 inline void free (void * ptr) {
40 heap1.free (ptr);
41 }
42
43 private:
44 Heap1 heap1;
45 };
46
47 }
48
49 #endif