Debian Codegraph @

vendor/Heap-Layers/heaps/utility/uniqueheap.h

raw symbols SCIP
1 // -*- C++ -*-cxx . . $ `<file>/vendor/Heap-Layers/heaps/utility/uniqueheap.h`/
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_UNIQUEHEAP_H
19 #define HL_UNIQUEHEAP_Hcxx . . $ `vendor/Heap-Layers/heaps/utility/uniqueheap.h:19:9`!
20
21 #include <cstdlib>
22 #include <new>
23
24 /**
25 *
26 * @class UniqueHeap
27 * @brief Instantiates one instance of a class used for every malloc & free.
28 * @author Emery Berger
29 *
30 */
31
32 namespace HLcxx . . $ HL/ {
33
34 template <class SuperHeap, class Child = int>
35 class UniqueHeapcxx . . $ HL/UniqueHeap# {
36 public:
37
38 enumcxx . . $ HL/UniqueHeap#$anonymous_type_0# { Alignmentcxx . . $ HL/UniqueHeap#Alignment. = SuperHeap::Alignment };
39
40 /**
41 * Ensure that the super heap gets created,
42 * and add a reference for every instance of unique heap.
43 */
44 UniqueHeapcxx . . $ HL/UniqueHeap#`UniqueHeap<SuperHeap, Child>`(49f6e7a06ebc5aa8).()
45 {
46 volatile SuperHeap * forceCreationOfSuperHeap __attribute__((unused)) = getSuperHeapcxx . . $ HL/UniqueHeap#getSuperHeap(155dc7f103cdb9db).();
47 addRefcxx . . $ HL/UniqueHeap#addRef(49f6e7a06ebc5aa8).();
48 }
49
50 /**
51 * @brief Delete one reference to the unique heap.
52 * When the number of references goes to zero,
53 * delete the super heap.
54 */
55 ~cxx . . $ HL/UniqueHeap#`~UniqueHeap<SuperHeap, Child>`(49f6e7a06ebc5aa8).UniqueHeap() {
56 int r = delRefcxx . . $ HL/UniqueHeap#delRef(b126dc7c1de90089).();
57 if (r <= 0) {
58 getSuperHeapcxx . . $ HL/UniqueHeap#getSuperHeap(155dc7f103cdb9db).()->SuperHeap::~SuperHeap();
59 }
60 }
61
62 // The remaining public methods are just
63 // thin wrappers that route calls to the static object.
64
65 inline void * malloccxx . . $ HL/UniqueHeap#malloc(bfcfa4d6b7f7ef64). (size_t sz) {
66 return getSuperHeapcxx . . $ HL/UniqueHeap#getSuperHeap(155dc7f103cdb9db).()->malloc (sz);
67 }
68
69 inline void freecxx . . $ HL/UniqueHeap#free(5d22bdacc48458e8). (void * ptr) {
70 getSuperHeapcxx . . $ HL/UniqueHeap#getSuperHeap(155dc7f103cdb9db).()->free (ptr);
71 }
72
73 inline size_t getSizecxx . . $ HL/UniqueHeap#getSize(751e5d26f8574c32). (void * ptr) {
74 return getSuperHeapcxx . . $ HL/UniqueHeap#getSuperHeap(155dc7f103cdb9db).()->getSize (ptr);
75 }
76
77 inline int removecxx . . $ HL/UniqueHeap#remove(dedf1e9b1c614a07). (void * ptr) {
78 return getSuperHeapcxx . . $ HL/UniqueHeap#getSuperHeap(155dc7f103cdb9db).()->remove (ptr);
79 }
80
81 inline void clearcxx . . $ HL/UniqueHeap#clear(49f6e7a06ebc5aa8).() {
82 getSuperHeapcxx . . $ HL/UniqueHeap#getSuperHeap(155dc7f103cdb9db).()->clear();
83 }
84
85 #if 0
86 inline int getAllocated() {
87 return getSuperHeap()->getAllocated();
88 }
89
90 inline int getMaxAllocated() {
91 return getSuperHeap()->getMaxAllocated();
92 }
93
94 inline int getMaxInUse() {
95 return getSuperHeap()->getMaxInUse();
96 }
97 #endif
98
99 private:
100
101 /// Add one reference.
102 void addRefcxx . . $ HL/UniqueHeap#addRef(49f6e7a06ebc5aa8).() {
103 getRefscxx . . $ HL/UniqueHeap#getRefs(ffa05e89dbf2c50f).() += 1;
104 }
105
106 /// Delete one reference count.
107 int delRefcxx . . $ HL/UniqueHeap#delRef(b126dc7c1de90089).() {
108 getRefscxx . . $ HL/UniqueHeap#getRefs(ffa05e89dbf2c50f).() -= 1;
109 return getRefscxx . . $ HL/UniqueHeap#getRefs(ffa05e89dbf2c50f).();
110 }
111
112 /// Internal accessor for reference count.
113 int& getRefscxx . . $ HL/UniqueHeap#getRefs(ffa05e89dbf2c50f).() {
114 static int numRefs = 0;
115 return numRefs;
116 }
117
118 SuperHeap * getSuperHeapcxx . . $ HL/UniqueHeap#getSuperHeap(155dc7f103cdb9db).() {
119 static char superHeapBuffer[sizeof(SuperHeap)];
120 static SuperHeap * aSuperHeap = (SuperHeap *) (new ((char *) &superHeapBuffer) SuperHeap);
121 return aSuperHeap;
122 }
123
124 void doNothingcxx . . $ HL/UniqueHeap#doNothing(b86249c387e65cb9). (Child *) {}
125 };
126
127 }
128 #endif // _UNIQUE_H_