CUBRID Engine
latest
Main Page
Namespaces
Classes
Files
File List
File Members
addheap.h
Go to the documentation of this file.
1
/* -*- C++ -*- */
2
3
#ifndef HL_ADDHEAP_H
4
#define HL_ADDHEAP_H
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
emery@cs.umass.edu
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
// Reserve space for a class in the head of every allocated object.
22
23
#include <assert.h>
24
#include "
utility/lcm.h
"
25
26
namespace
HL
{
27
28
template
<
class
Add,
class
SuperHeap>
29
class
AddHeap
:
public
SuperHeap {
30
public
:
31
32
inline
void
*
malloc
(
size_t
sz) {
33
void
* ptr = SuperHeap::malloc (sz +
HeaderSize
);
34
void
* newPtr = (
char
*) ptr +
HeaderSize
;
35
return
newPtr;
36
}
37
38
inline
void
free
(
void
* ptr) {
39
SuperHeap::free (
getOriginal
(ptr));
40
}
41
42
inline
size_t
getSize
(
void
* ptr) {
43
return
SuperHeap::getSize (
getOriginal
(ptr));
44
}
45
46
private
:
47
48
inline
void
*
getOriginal
(
void
* ptr) {
49
void
* origPtr = (
void
*) ((
char
*) ptr -
HeaderSize
);
50
return
origPtr;
51
}
52
53
// A size that preserves existing alignment restrictions.
54
// Beware: can seriously increase size requirements.
55
enum
{
HeaderSize
=
lcm<(int) SuperHeap::Alignment, sizeof(Add)>::value
};
56
57
};
58
59
}
60
#endif
HL::AddHeap
Definition:
addheap.h:29
HL::lcm
Definition:
lcm.h:11
HL
Definition:
heaplayers.h:34
HL::AddHeap::free
void free(void *ptr)
Definition:
addheap.h:38
lcm.h
HL::AddHeap::malloc
void * malloc(size_t sz)
Definition:
addheap.h:32
HL::AddHeap::HeaderSize
Definition:
addheap.h:55
HL::AddHeap::getOriginal
void * getOriginal(void *ptr)
Definition:
addheap.h:48
HL::AddHeap::getSize
size_t getSize(void *ptr)
Definition:
addheap.h:42
src
heaplayers
heaps
objectrep
addheap.h
Generated by
1.8.11