CUBRID Engine
latest
Main Page
Namespaces
Classes
Files
File List
File Members
freelistheap.h
Go to the documentation of this file.
1
/* -*- C++ -*- */
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
emery@cs.umass.edu
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_FREELISTHEAP_H
19
#define HL_FREELISTHEAP_H
20
30
#include <assert.h>
31
#include "
utility/freesllist.h
"
32
33
#ifndef NULL
34
#define NULL 0
35
#endif
36
37
namespace
HL
{
38
39
template
<
class
SuperHeap>
40
class
FreelistHeap
:
public
SuperHeap {
41
public
:
42
43
inline
void
*
malloc
(
size_t
sz) {
44
// Check the free list first.
45
void
* ptr =
_freelist
.
get
();
46
// If it's empty, get more memory;
47
// otherwise, advance the free list pointer.
48
if
(ptr == 0) {
49
ptr = SuperHeap::malloc (sz);
50
}
51
return
ptr;
52
}
53
54
inline
void
free
(
void
* ptr) {
55
if
(ptr == 0) {
56
return
;
57
}
58
_freelist
.
insert
(ptr);
59
}
60
61
inline
void
clear
(
void
) {
62
void
* ptr;
63
while
((ptr =
_freelist
.
get
())) {
64
SuperHeap::free (ptr);
65
}
66
}
67
68
private
:
69
70
FreeSLList
_freelist
;
71
72
};
73
74
}
75
76
#endif
FreeSLList::get
Entry * get(void)
Get the head of the list.
Definition:
freesllist.h:27
FreeSLList::insert
void insert(void *e)
Definition:
freesllist.h:45
HL
Definition:
heaplayers.h:34
HL::FreelistHeap
Definition:
freelistheap.h:40
HL::FreelistHeap::_freelist
FreeSLList _freelist
Definition:
freelistheap.h:70
freesllist.h
HL::FreelistHeap::malloc
void * malloc(size_t sz)
Definition:
freelistheap.h:43
HL::FreelistHeap::free
void free(void *ptr)
Definition:
freelistheap.h:54
HL::FreelistHeap::clear
void clear(void)
Definition:
freelistheap.h:61
FreeSLList
A "memory neutral" singly-linked list,.
Definition:
freesllist.h:17
src
heaplayers
heaps
buildingblock
freelistheap.h
Generated by
1.8.11