Debian Codegraph @

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

raw symbols SCIP
1 // -*- C++ -*-cxx . . $ `<file>/vendor/Heap-Layers/heaps/utility/slopheap.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_SLOPHEAP_H
19 #define HL_SLOPHEAP_Hcxx . . $ `vendor/Heap-Layers/heaps/utility/slopheap.h:19:9`!
20
21 #include <cstddef>
22
23 /**
24 * @class SlopHeap
25 *
26 * SlopHeap is designed to guarantee that you always have an extra N bytes
27 * available after the most recent malloc. This is necessary for the current
28 * coalescing support, which can look past the last allocated object.
29 *
30 * @param SuperHeap The parent heap.
31 * @param SLOP The amount of extra memory required, in bytes.
32 */
33
34 namespace HLcxx . . $ HL/ {
35
36 template <class SuperHeap, int SLOP = 16>
37 class SlopHeapcxx . . $ HL/SlopHeap# : public SuperHeap {
38 public:
39 SlopHeapcxx . . $ HL/SlopHeap#`SlopHeap<SuperHeap, SLOP>`(49f6e7a06ebc5aa8). (void)
40 : remainingcxx . . $ HL/SlopHeap#remaining. (0),
41 ptrcxx . . $ HL/SlopHeap#ptr. (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
42 {}
43
44 inline void * malloccxx . . $ HL/SlopHeap#malloc(bfcfa4d6b7f7ef64). (const size_t nbytes) {
45
46 // Put the usual case up front.
47 if (nbytes <= remainingcxx . . $ HL/SlopHeap#remaining.) {
48 remainingcxx . . $ HL/SlopHeap#remaining. -= nbytes;
49 char * p = ptrcxx . . $ HL/SlopHeap#ptr.;
50 ptrcxx . . $ HL/SlopHeap#ptr. += nbytes;
51 return (void *) p;
52 }
53
54 //
55 // We don't have enough space to satisfy the current
56 // request, so get more memory.
57 //
58
59 return getMoreMemorycxx . . $ HL/SlopHeap#getMoreMemory(bfcfa4d6b7f7ef64).(nbytes);
60 }
61
62 inline void clearcxx . . $ HL/SlopHeap#clear(49f6e7a06ebc5aa8). (void) {
63 ptrcxx . . $ HL/SlopHeap#ptr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
64 remainingcxx . . $ HL/SlopHeap#remaining. = 0;
65 SuperHeap::clear ();
66 }
67
68 inline void freecxx . . $ HL/SlopHeap#free(5d22bdacc48458e8). (void *) {}
69
70 private:
71
72 // Disabled.
73 inline int removecxx . . $ HL/SlopHeap#remove(dedf1e9b1c614a07). (void *);
74
75 void * getMoreMemorycxx . . $ HL/SlopHeap#getMoreMemory(bfcfa4d6b7f7ef64). (size_t nbytes) {
76 char * newptr = (char *) SuperHeap::malloc (nbytes + SLOP);
77
78 if (newptr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
79 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
80 }
81
82 //
83 // If this new memory is contiguous with the previous one,
84 // reclaim the "slop".
85 //
86
87 if ((ptrcxx . . $ HL/SlopHeap#ptr. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) && (ptrcxx . . $ HL/SlopHeap#ptr. + remainingcxx . . $ HL/SlopHeap#remaining. + SLOP == newptr)) {
88 remainingcxx . . $ HL/SlopHeap#remaining. += SLOP;
89 } else {
90 ptrcxx . . $ HL/SlopHeap#ptr. = newptr;
91 remainingcxx . . $ HL/SlopHeap#remaining. = 0;
92 }
93 char * p = ptrcxx . . $ HL/SlopHeap#ptr.;
94 ptrcxx . . $ HL/SlopHeap#ptr. += nbytes;
95
96 return (void *) p;
97 }
98
99 char * ptrcxx . . $ HL/SlopHeap#ptr.;
100 size_t remainingcxx . . $ HL/SlopHeap#remaining.;
101
102 };
103
104 }
105
106 #endif