Debian Codegraph @

vendor/Heap-Layers/heaps/buildingblock/chunkheap.h

raw symbols SCIP
1 /* -*- C++ -*- */cxx . . $ `<file>/vendor/Heap-Layers/heaps/buildingblock/chunkheap.h`/
2
3 #ifndef HL_CHUNKHEAP_H_
4 #define HL_CHUNKHEAP_H_cxx . . $ `vendor/Heap-Layers/heaps/buildingblock/chunkheap.h:4:9`!
5
6 /*
7
8 Heap Layers: An Extensible Memory Allocation Infrastructure
9
10 Copyright (C) 2000-2020 by Emery Berger
11 http://www.emeryberger.com
12 [email protected]
13
14 Heap Layers is distributed under the terms of the Apache 2.0 license.
15
16 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
18
19 */
20
21 #include <assert.h>
22
23 /**
24 * @class ChunkHeap
25 * @brief Allocates memory from the superheap in chunks.
26 * @param ChunkSize The minimum size for allocating memory from the superheap.
27 */
28
29 namespace HLcxx . . $ HL/ {
30
31 template <int ChunkSize, class SuperHeap>
32 class ChunkHeapcxx . . $ HL/ChunkHeap# : public SuperHeap {
33 public:
34
35 inline ChunkHeapcxx . . $ HL/ChunkHeap#`ChunkHeap<ChunkSize, SuperHeap>`(49f6e7a06ebc5aa8). (void)
36 : buffercxx . . $ HL/ChunkHeap#buffer. (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!),
37 eobcxx . . $ HL/ChunkHeap#eob. (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
38 {}
39
40 inline void * malloccxx . . $ HL/ChunkHeap#malloc(bfcfa4d6b7f7ef64). (const size_t sz) {
41 void * ptr = buffercxx . . $ HL/ChunkHeap#buffer.;
42 buffercxx . . $ HL/ChunkHeap#buffer. += sz;
43 if (buffercxx . . $ HL/ChunkHeap#buffer. <= eobcxx . . $ HL/ChunkHeap#eob.) {
44 assertcxx . . $ `/usr/include/assert.h:50:10`! (eob != NULL);
45 assertcxx . . $ `/usr/include/assert.h:50:10`! ((size_t) (eob - (char *) ptr + 1) >= sz);
46 return ptr;
47 }
48 buffercxx . . $ HL/ChunkHeap#buffer. -= sz; // we didn't succeed, back up
49 return getMoreMemorycxx . . $ HL/ChunkHeap#getMoreMemory(bfcfa4d6b7f7ef64).(sz);
50 }
51
52 inline void clearcxx . . $ HL/ChunkHeap#clear(49f6e7a06ebc5aa8). (void) {
53 buffercxx . . $ HL/ChunkHeap#buffer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
54 eobcxx . . $ HL/ChunkHeap#eob. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
55 SuperHeap::clear ();
56 }
57
58 private:
59
60 // Disabled.
61 inline int removecxx . . $ HL/ChunkHeap#remove(dedf1e9b1c614a07). (void *);
62
63 void * getMoreMemorycxx . . $ HL/ChunkHeap#getMoreMemory(bfcfa4d6b7f7ef64). (size_t sz) {
64 assertcxx . . $ `/usr/include/assert.h:50:10`! (sz > 0);
65 // Round sz to the next chunk size.
66 size_t reqSize = (((sz-1) / ChunkSize) + 1) * ChunkSize;
67 char * buf = (char *) SuperHeap::malloc (reqSize);
68 if (buf == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
69 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
70 }
71 // If the current end of buffer is not the same as the new buffer,
72 // reset the buffer pointer.
73 if (eobcxx . . $ HL/ChunkHeap#eob. != buf) {
74 buffercxx . . $ HL/ChunkHeap#buffer. = buf;
75 }
76 else {
77 // we still have a bit leftover at the end of previous buffer
78 reqSize += eobcxx . . $ HL/ChunkHeap#eob. - buffercxx . . $ HL/ChunkHeap#buffer.;
79 }
80 eobcxx . . $ HL/ChunkHeap#eob. = buffercxx . . $ HL/ChunkHeap#buffer. + reqSize;
81
82 void * ptr = buffercxx . . $ HL/ChunkHeap#buffer.;
83 buffercxx . . $ HL/ChunkHeap#buffer. += sz;
84 return ptr;
85 }
86
87 /// The current allocation buffer.
88 char * buffercxx . . $ HL/ChunkHeap#buffer.;
89
90 /// The end of the buffer.
91 char * eobcxx . . $ HL/ChunkHeap#eob.;
92 };
93
94 }
95
96 #endif