Debian Codegraph @

vendor/Heap-Layers/heaps/special/zoneheap.h

raw symbols SCIP
1 /* -*- C++ -*- */cxx . . $ `<file>/vendor/Heap-Layers/heaps/special/zoneheap.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 /**
19 * @class ZoneHeap
20 * @brief A zone (or arena, or region) based allocator.
21 * @author Emery Berger
22 *
23 * Uses the superclass to obtain large chunks of memory that are only
24 * returned when the heap itself is destroyed.
25 *
26 */
27
28 #ifndef HL_ZONEHEAP_H
29 #define HL_ZONEHEAP_Hcxx . . $ `vendor/Heap-Layers/heaps/special/zoneheap.h:29:9`!
30
31 #include <assert.h>
32
33 #include "utility/align.h"cxx . . $ `<file>/vendor/Heap-Layers/utility/align.h`/
34 #include "wrappers/mallocinfo.h"cxx . . $ `<file>/vendor/Heap-Layers/wrappers/mallocinfo.h`/
35
36 namespace HLcxx . . $ HL/ {
37
38 template <class SuperHeap, size_t ChunkSize>
39 class ZoneHeapcxx . . $ HL/ZoneHeap# : public SuperHeap {
40 public:
41
42 enumcxx . . $ HL/ZoneHeap#$anonymous_type_0# { Alignmentcxx . . $ HL/ZoneHeap#Alignment. = SuperHeap::Alignment };
43
44 ZoneHeapcxx . . $ HL/ZoneHeap#`ZoneHeap<SuperHeap, ChunkSize>`(49f6e7a06ebc5aa8).()
45 : _sizeRemainingcxx . . $ HL/ZoneHeap#_sizeRemaining. (0),
46 _currentArenacxx . . $ HL/ZoneHeap#_currentArena. (nullptr),
47 _pastArenascxx . . $ HL/ZoneHeap#_pastArenas. (nullptr)
48 {}
49
50 ~cxx . . $ HL/ZoneHeap#`~ZoneHeap<SuperHeap, ChunkSize>`(49f6e7a06ebc5aa8).ZoneHeap()
51 {
52 clearcxx . . $ HL/ZoneHeap#clear(49f6e7a06ebc5aa8).();
53 }
54
55 inline void * malloccxx . . $ HL/ZoneHeap#malloc(bfcfa4d6b7f7ef64). (size_t sz) {
56 void * ptr = zoneMalloccxx . . $ HL/ZoneHeap#zoneMalloc(bfcfa4d6b7f7ef64). (sz);
57 // assert ((size_t) ptr % Alignment == 0);
58 return ptr;
59 }
60
61 /// Free in a zone allocator is a no-op.
62 inline void freecxx . . $ HL/ZoneHeap#free(5d22bdacc48458e8). (void *) {}
63
64 /// Remove in a zone allocator is a no-op.
65 inline int removecxx . . $ HL/ZoneHeap#remove(dedf1e9b1c614a07). (void *) { return 0; }
66
67 void clearcxx . . $ HL/ZoneHeap#clear(49f6e7a06ebc5aa8).() {
68 // printf ("deleting arenas!\n");
69 // Delete all of our arenas.
70 Arenacxx . . $ HL/ZoneHeap#Arena# * ptr = _pastArenascxx . . $ HL/ZoneHeap#_pastArenas.;
71 while (ptr !=cxx . . $ std/`operator!=`(39b98f4fe21ae589). nullptr) {
72 auto oldPtr = ptr;
73 ptr = ptr->nextArenacxx . . $ HL/ZoneHeap#Arena#nextArena.;
74 SuperHeap::free (oldPtr, oldPtr->arenaSize);
75 }
76 if (_currentArenacxx . . $ HL/ZoneHeap#_currentArena. !=cxx . . $ std/`operator!=`(39b98f4fe21ae589). nullptr) {
77 //printf ("deleting %x\n", _currentArena);
78 SuperHeap::free ((void *) _currentArenacxx . . $ HL/ZoneHeap#_currentArena., _currentArenacxx . . $ HL/ZoneHeap#_currentArena.->arenaSizecxx . . $ HL/ZoneHeap#Arena#arenaSize.);
79 }
80 _currentArenacxx . . $ HL/ZoneHeap#_currentArena. = nullptr;
81 _sizeRemainingcxx . . $ HL/ZoneHeap#_sizeRemaining. = 0;
82 _pastArenascxx . . $ HL/ZoneHeap#_pastArenas. = nullptr;
83 }
84
85 private:
86
87 ZoneHeapcxx . . $ HL/ZoneHeap#`ZoneHeap<SuperHeap, ChunkSize>`(31cc6cde554f5c69). (const ZoneHeap&);
88 ZoneHeap& operatorcxx . . $ HL/ZoneHeap#`operator=`(ef810688f64a0502).=(const ZoneHeap&);
89
90 inline void * zoneMalloccxx . . $ HL/ZoneHeap#zoneMalloc(bfcfa4d6b7f7ef64). (size_t sz) {
91 void * ptr;
92 // Round up size to an aligned value.
93 sz = HLcxx . . $ HL/::aligncxx . . $ HL/align(ecdaa1632f49f591).<HLcxx . . $ HL/::MallocInfocxx . . $ HL/MallocInfo#::Alignmentcxx . . $ HL/MallocInfo#Alignment.>(sz);
94 // Get more space in our arena if there's not enough room in this one.
95 if ((_currentArenacxx . . $ HL/ZoneHeap#_currentArena. ==cxx . . $ std/`operator==`(39b98f4fe21ae589). nullptr) || (_sizeRemainingcxx . . $ HL/ZoneHeap#_sizeRemaining. < sz)) {
96 // First, add this arena to our past arena list.
97 if (_currentArenacxx . . $ HL/ZoneHeap#_currentArena. !=cxx . . $ std/`operator!=`(39b98f4fe21ae589). nullptr) {
98 _currentArenacxx . . $ HL/ZoneHeap#_currentArena.->nextArenacxx . . $ HL/ZoneHeap#Arena#nextArena. = _pastArenascxx . . $ HL/ZoneHeap#_pastArenas.;
99 _pastArenascxx . . $ HL/ZoneHeap#_pastArenas. = _currentArenacxx . . $ HL/ZoneHeap#_currentArena.;
100 }
101 // Now get more memory.
102 size_t allocSize = ChunkSize;
103 if (allocSize < sz) {
104 allocSize = sz;
105 }
106 _currentArenacxx . . $ HL/ZoneHeap#_currentArena. =
107 (Arenacxx . . $ HL/ZoneHeap#Arena# *) SuperHeap::malloc (allocSize + sizeof(Arenacxx . . $ HL/ZoneHeap#Arena#));
108 if (_currentArenacxx . . $ HL/ZoneHeap#_currentArena. ==cxx . . $ std/`operator==`(39b98f4fe21ae589). nullptr) {
109 return nullptr;
110 }
111 _currentArenacxx . . $ HL/ZoneHeap#_currentArena.->arenaSpacecxx . . $ HL/ZoneHeap#Arena#arenaSpace. = (char *) (_currentArenacxx . . $ HL/ZoneHeap#_currentArena. +cxx . . $ std/operator+(933aeee3a62e2e30). 1);
112 _currentArenacxx . . $ HL/ZoneHeap#_currentArena.->nextArenacxx . . $ HL/ZoneHeap#Arena#nextArena. = nullptr;
113 _currentArenacxx . . $ HL/ZoneHeap#_currentArena.->arenaSizecxx . . $ HL/ZoneHeap#Arena#arenaSize. = allocSize + sizeof(Arenacxx . . $ HL/ZoneHeap#Arena#);
114 _sizeRemainingcxx . . $ HL/ZoneHeap#_sizeRemaining. = allocSize;
115 }
116 // Bump the pointer and update the amount of memory remaining.
117 _sizeRemainingcxx . . $ HL/ZoneHeap#_sizeRemaining. -= sz;
118 ptr = _currentArenacxx . . $ HL/ZoneHeap#_currentArena.->arenaSpacecxx . . $ HL/ZoneHeap#Arena#arenaSpace.;
119 _currentArenacxx . . $ HL/ZoneHeap#_currentArena.->arenaSpacecxx . . $ HL/ZoneHeap#Arena#arenaSpace. += sz;
120 assertcxx . . $ `/usr/include/assert.h:50:10`! (ptr != nullptr);
121 // assert ((size_t) ptr % SuperHeap::Alignment == 0);
122 return ptr;
123 }
124
125 class Arenacxx . . $ HL/ZoneHeap#Arena# {
126 public:
127 Arenacxx . . $ HL/ZoneHeap#Arena#Arena(49f6e7a06ebc5aa8).() {
128 static_assert((sizeof(Arenacxx . . $ HL/ZoneHeap#Arena#) % HLcxx . . $ HL/::MallocInfocxx . . $ HL/MallocInfo#::Alignmentcxx . . $ HL/MallocInfo#Alignment. == 0),
129 "Alignment must match Arena size.");
130 }
131
132 Arenacxx . . $ HL/ZoneHeap#Arena# * nextArenacxx . . $ HL/ZoneHeap#Arena#nextArena.;
133 char * arenaSpacecxx . . $ HL/ZoneHeap#Arena#arenaSpace.;
134 size_t arenaSizecxx . . $ HL/ZoneHeap#Arena#arenaSize.;
135 };
136
137 /// Space left in the current arena.
138 size_t _sizeRemainingcxx . . $ HL/ZoneHeap#_sizeRemaining.;
139
140 /// The current arena.
141 Arenacxx . . $ HL/ZoneHeap#Arena# * _currentArenacxx . . $ HL/ZoneHeap#_currentArena.;
142
143 /// A linked list of past arenas.
144 Arenacxx . . $ HL/ZoneHeap#Arena# * _pastArenascxx . . $ HL/ZoneHeap#_pastArenas.;
145 };
146
147 }
148
149 #endif