Debian Codegraph @

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

raw symbols SCIP
1 // -*- C++ -*-cxx . . $ `<file>/vendor/Heap-Layers/heaps/combining/strictsegheap.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 * @file strictsegheap.h
20 * @brief Definition of StrictSegHeap.
21 */
22
23 #ifndef HL_STRICTSEGHEAP_H
24 #define HL_STRICTSEGHEAP_Hcxx . . $ `vendor/Heap-Layers/heaps/combining/strictsegheap.h:24:9`!
25
26 #include "segheap.h"cxx . . $ `<file>/vendor/Heap-Layers/heaps/combining/segheap.h`/
27
28 /**
29 * @class StrictSegHeap
30 * @brief A "strict" segregated-fits collection of (homogeneous) heaps.
31 *
32 * One extra heap is used for objects that are "too big". Unlike
33 * SegHeap, StrictSegHeap does not perform splitting to satisfy memory
34 * requests. If no memory is available from the appropriate bin,
35 * malloc returns NULL.
36 *
37 * @sa SegHeap
38 *
39 * @param NumBins The number of bins (subheaps).
40 * @param getSizeClass Function to compute size class from size.
41 * @param getClassMaxSize Function to compute the largest size for a given size class.
42 * @param LittleHeap The subheap class.
43 * @param BigHeap The parent class, used for "big" objects.
44 */
45
46 namespace HLcxx . . $ HL/ {
47
48 template <int NumBins,
49 int (*size2class) (const size_t),
50 size_t (*class2size) (const int),
51 class LittleHeap,
52 class BigHeap>
53 class StrictSegHeapcxx . . $ HL/StrictSegHeap# :
54 public SegHeapcxx . . $ HL/SegHeap#<NumBins, size2class, class2size, LittleHeap, BigHeap>
55 {
56 private:
57
58 typedef SegHeapcxx . . $ HL/SegHeap#<NumBins, size2class, class2size, LittleHeap, BigHeap> SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#;
59
60 public:
61
62 static constexpr size_t num_size_classescxx . . $ HL/StrictSegHeap#num_size_classes. = NumBins;
63 int get_size_classcxx . . $ HL/StrictSegHeap#get_size_class(e3044d25979e9615).(const size_t sz) const { return size2class(sz); }
64 size_t get_class_sizecxx . . $ HL/StrictSegHeap#get_class_size(79dc3568750208f6).(int i) const { return class2size(i); }
65
66 void clearcxx . . $ HL/StrictSegHeap#clear(49f6e7a06ebc5aa8). () {
67 for (auto i = 0; i < NumBins; i++) {
68 const size_t sz = class2size(i);
69 void * ptr;
70 while ((ptr = SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::myLittleHeap[i].malloc (sz)) !=cxx . . $ HL/`operator!=`(fef5daa2f5cf3d2). NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
71 SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::bigheap.free (ptr);
72 }
73 }
74 for (auto j = 0; j <cxx . . $ std/`operator<`(39b98f4fe21ae589). SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::NUM_ULONGS; j++) {
75 SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::binmap[j] = 0;
76 }
77 SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::_memoryHeld = 0;
78 }
79
80 /**
81 * Malloc from exactly one available size.
82 * (don't look in every small heap, as in SegHeap).
83 */
84
85 inline void * malloccxx . . $ HL/StrictSegHeap#malloc(bfcfa4d6b7f7ef64). (const size_t sz) {
86 void * ptr = nullptr;
87 const auto sizeClass = size2class(sz);
88 const auto realSize = class2size(sizeClass);
89
90 assertcxx . . $ `/usr/include/assert.h:50:10`! (realSize >= sz);
91
92 if (realSize <=cxx . . $ std/`operator<=`(39b98f4fe21ae589). SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::_maxObjectSize) {
93 assertcxx . . $ `/usr/include/assert.h:50:10`! (sizeClass >= 0);
94 assertcxx . . $ `/usr/include/assert.h:50:10`! (sizeClass < NumBins);
95 ptr = SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::myLittleHeap[sizeClass].malloc (realSize);
96 }
97 if (!ptr) {
98 ptr = SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::bigheap.malloc (realSize);
99 }
100 return ptr;
101 }
102
103 inline void freecxx . . $ HL/StrictSegHeap#free(5d22bdacc48458e8). (void * ptr) {
104 const auto objectSize = SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::getSize(ptr);
105 freecxx . . $ HL/StrictSegHeap#free(5d22bdacc48458e8).(ptr, objectSize);
106 }
107
108 inline void freecxx . . $ HL/StrictSegHeap#free(5500c4293b1bbef0).(void * ptr, size_t objectSize) {
109 if (objectSize >cxx . . $ std/`operator>`(39b98f4fe21ae589). SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::_maxObjectSize) {
110 SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::bigheap.free (ptr);
111 } else {
112 auto objectSizeClass = size2class(objectSize);
113 assertcxx . . $ `/usr/include/assert.h:50:10`! (objectSizeClass >= 0);
114 assertcxx . . $ `/usr/include/assert.h:50:10`! (objectSizeClass < NumBins);
115 assertcxx . . $ `/usr/include/assert.h:50:10`! (class2size(objectSizeClass) >= objectSize);
116
117 // Put the freed object into the right sizeclass heap.
118
119 // Ensure that the bin that we are going to put it in is for
120 // objects that are no bigger than the actual size of the
121 // object. Ensure we don't run forever.
122
123 while ((objectSizeClass > 0) &&
124 (class2size(objectSizeClass) > objectSize)) {
125 objectSizeClass--;
126 }
127 // Leak objects if something went wrong.
128 if (class2size(objectSizeClass) >= objectSize) {
129 SuperHeapcxx . . $ HL/StrictSegHeap#SuperHeap#::myLittleHeap[objectSizeClass].free (ptr);
130 }
131 }
132 }
133
134 };
135
136 }
137
138 #endif
139