Debian Codegraph @

vendor/Heap-Layers/heaps/objectrep/sizeheap.h

raw symbols SCIP
1 /* -*- C++ -*- */cxx . . $ `<file>/vendor/Heap-Layers/heaps/objectrep/sizeheap.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_SIZEHEAP_H
19 #define HL_SIZEHEAP_Hcxx . . $ `vendor/Heap-Layers/heaps/objectrep/sizeheap.h:19:9`!
20
21 /**
22 * @file sizeheap.h
23 * @brief Contains UseSizeHeap and SizeHeap.
24 */
25
26 #include <assert.h>
27
28 #include "wrappers/mallocinfo.h"cxx . . $ `<file>/vendor/Heap-Layers/wrappers/mallocinfo.h`/
29 #include "heaps/objectrep/addheap.h"cxx . . $ `<file>/vendor/Heap-Layers/heaps/objectrep/addheap.h`/
30 #include "utility/gcd.h"cxx . . $ `<file>/vendor/Heap-Layers/utility/gcd.h`/
31
32 namespace HLcxx . . $ HL/ {
33
34 /**
35 * @class SizeHeap
36 * @brief Allocates extra room for the size of an object.
37 */
38
39 template <class SuperHeap>
40 class SizeHeapcxx . . $ HL/SizeHeap# : public SuperHeap {
41
42 private:
43 struct freeObjectcxx . . $ HL/SizeHeap#freeObject# {
44 size_t _szcxx . . $ HL/SizeHeap#freeObject#_sz.;
45 size_t _magiccxx . . $ HL/SizeHeap#freeObject#_magic.;
46 // char _buf[HL::MallocInfo::Alignment];
47 };
48
49 enumcxx . . $ HL/SizeHeap#$anonymous_type_0# { MAGIC_NUMBERcxx . . $ HL/SizeHeap#MAGIC_NUMBER. = 0xCAFEBABE };
50
51 public:
52
53 enumcxx . . $ HL/SizeHeap#$anonymous_type_1# { Alignmentcxx . . $ HL/SizeHeap#Alignment. = gcdcxx . . $ HL/gcd#<(int) SuperHeap::Alignment,
54 (int) sizeof(freeObject)>::value };
55
56 virtual ~cxx . . $ HL/SizeHeap#`~SizeHeap<SuperHeap>`(49f6e7a06ebc5aa8).SizeHeap (void) {}
57
58 inline void * malloccxx . . $ HL/SizeHeap#malloc(bfcfa4d6b7f7ef64). (size_t sz) {
59 freeObjectcxx . . $ HL/SizeHeap#freeObject# * p = (freeObjectcxx . . $ HL/SizeHeap#freeObject# *) SuperHeap::malloc (sz + sizeof(freeObjectcxx . . $ HL/SizeHeap#freeObject#));
60 p->_szcxx . . $ HL/SizeHeap#freeObject#_sz. = sz;
61 p->_magiccxx . . $ HL/SizeHeap#freeObject#_magic. = MAGIC_NUMBERcxx . . $ HL/SizeHeap#MAGIC_NUMBER.;
62 return (void *) (p +cxx . . $ std/operator+(933aeee3a62e2e30). 1);
63 }
64
65 inline void freecxx . . $ HL/SizeHeap#free(5d22bdacc48458e8). (void * ptr) {
66 if (getHeadercxx . . $ HL/SizeHeap#getHeader(42996130af5ebb5).(ptr)->_magic ==cxx . . $ HL/`operator==`(fef5daa2f5cf3d2). MAGIC_NUMBERcxx . . $ HL/SizeHeap#MAGIC_NUMBER.) {
67 // Probably one of our objects.
68 SuperHeap::free (getHeadercxx . . $ HL/SizeHeap#getHeader(42996130af5ebb5).(ptr));
69 }
70 }
71
72 inline static size_t getSizecxx . . $ HL/SizeHeap#getSize(2e8e543e1193434e). (const void * ptr) {
73 if (getHeadercxx . . $ HL/SizeHeap#getHeader(42996130af5ebb5).(ptr)->_magic ==cxx . . $ HL/`operator==`(fef5daa2f5cf3d2). MAGIC_NUMBERcxx . . $ HL/SizeHeap#MAGIC_NUMBER.) {
74 size_t size = getHeadercxx . . $ HL/SizeHeap#getHeader(42996130af5ebb5).(ptr)->_sz;
75 return size;
76 } else {
77 // Probably not one of our objects.
78 return 0;
79 }
80 }
81
82 private:
83
84 inline static void setSizecxx . . $ HL/SizeHeap#setSize(5500c4293b1bbef0). (void * ptr, size_t sz) {
85 assertcxx . . $ `/usr/include/assert.h:50:10`! (getHeader(ptr)->_magic == MAGIC_NUMBER);
86 getHeadercxx . . $ HL/SizeHeap#getHeader(42996130af5ebb5).(ptr)->_sz = sz;
87 }
88
89 inline static freeObjectcxx . . $ HL/SizeHeap#freeObject# * getHeadercxx . . $ HL/SizeHeap#getHeader(42996130af5ebb5). (const void * ptr) {
90 return ((freeObjectcxx . . $ HL/SizeHeap#freeObject# *) ptr -cxx . . $ std/operator-(a6e85813984128c7). 1);
91 }
92
93 };
94
95 }
96
97 #endif