ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
Allocators.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*--------------------------- File Allocators.h ----------------------------*/
3
/*--------------------------------------------------------------------------*/
47
/*--------------------------------------------------------------------------*/
48
/*----------------------------- DEFINITIONS --------------------------------*/
49
/*--------------------------------------------------------------------------*/
50
51
#ifndef __ADS_Allocators
52
#define __ADS_Allocators
53
/* self-identification: #endif constant */
54
55
/*--------------------------------------------------------------------------*/
56
/*------------------------------ INCLUDES ----------------------------------*/
57
/*--------------------------------------------------------------------------*/
58
59
#include "
ADS/Contract.h
"
60
61
#include <cstddef>
62
#include <limits>
63
#include <map>
64
#include <set>
65
#include <vector>
66
67
/*--------------------------------------------------------------------------*/
68
/*--------------------------- NAMESPACE ------------------------------------*/
69
/*--------------------------------------------------------------------------*/
70
71
namespace
ADS
72
{
73
74
/*--------------------------------------------------------------------------*/
75
/*------------------------ CLASS BoundaryTagAllocator ----------------------*/
76
/*--------------------------------------------------------------------------*/
77
79
class
BoundaryTagAllocator
80
{
81
82
/*--------------------------------------------------------------------------*/
83
public
:
85
enum class
Fit
{
86
FIRST
,
87
BEST
,
88
NEXT
89
};
90
93
explicit
BoundaryTagAllocator
(
long
N ,
Fit
fit =
Fit::FIRST
);
94
121
long
allocate
(
long
n );
122
143
void
free
(
long
a );
144
146
[[nodiscard]]
long
freeWords
(
void
)
const
;
147
149
[[nodiscard]]
long
freeBlocks
(
void
)
const
;
150
151
/*--------------------------------------------------------------------------*/
152
private
:
153
// a block of s words at p: M[ p ] = M[ p + s - 1 ] = +s if free, -s if in
154
// use; a free block has also M[ p + 1 ] = next, M[ p + 2 ] = prev on the
155
// list of the free blocks, whose head is the place N (two extra words)
156
157
void
unlink(
long
p );
158
void
link(
long
p );
159
161
[[nodiscard]]
bool
tiled(
void
)
const
;
162
163
std::vector< long > M;
164
long
N;
165
Fit
f_fit;
166
long
f_rover;
167
std::set< long > f_used;
168
169
};
// end( class BoundaryTagAllocator )
170
171
/*--------------------------------------------------------------------------*/
172
/*-------------------------- CLASS BuddyAllocator --------------------------*/
173
/*--------------------------------------------------------------------------*/
174
176
class
BuddyAllocator
177
{
178
179
/*--------------------------------------------------------------------------*/
180
public
:
184
explicit
BuddyAllocator
(
int
m );
185
207
long
allocate
(
long
n );
208
224
void
free
(
long
a );
225
227
[[nodiscard]]
long
freeWords
(
void
)
const
;
228
231
[[nodiscard]]
long
blockSize
(
long
a )
const
;
232
233
/*--------------------------------------------------------------------------*/
234
private
:
236
[[nodiscard]]
bool
merged(
void
)
const
;
237
238
int
f_m;
239
std::vector< std::set< long > > f_free;
240
std::map< long , int > f_used;
241
242
};
// end( class BuddyAllocator )
243
244
/*--------------------------------------------------------------------------*/
245
246
}
// end( namespace ADS )
247
248
/*--------------------------------------------------------------------------*/
249
/*-------------------------- IMPLEMENTATION --------------------------------*/
250
/*--------------------------------------------------------------------------*/
251
252
#include "ADS/memory/impl/Allocators.tpp"
253
254
/*--------------------------------------------------------------------------*/
255
256
#endif
/* Allocators.h included */
257
258
/*--------------------------------------------------------------------------*/
259
/*------------------------- End File Allocators.h --------------------------*/
260
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ADS::BoundaryTagAllocator::freeBlocks
long freeBlocks(void) const
the number of the free blocks
ADS::BoundaryTagAllocator::BoundaryTagAllocator
BoundaryTagAllocator(long N, Fit fit=Fit::FIRST)
the memory of words, one free block, with the choice fit
ADS::BoundaryTagAllocator::Fit
Fit
the block chosen for a request
Definition
Allocators.h:85
ADS::BoundaryTagAllocator::Fit::FIRST
@ FIRST
the first one large enough on the list (Algorithm 2.5A)
Definition
Allocators.h:86
ADS::BoundaryTagAllocator::Fit::NEXT
@ NEXT
the first one large enough after the last one given
Definition
Allocators.h:88
ADS::BoundaryTagAllocator::Fit::BEST
@ BEST
the smallest one large enough
Definition
Allocators.h:87
ADS::BoundaryTagAllocator::freeWords
long freeWords(void) const
the number of the words in free blocks, tags included
ADS::BoundaryTagAllocator::allocate
long allocate(long n)
a block of at least words, its first word, or
ADS::BoundaryTagAllocator::free
void free(long a)
frees the block whose first word is
ADS::BuddyAllocator::allocate
long allocate(long n)
a block of at least words, a power of 2, its address, or
ADS::BuddyAllocator::blockSize
long blockSize(long a) const
the size of the block in use at
ADS::BuddyAllocator::free
void free(long a)
frees the block at
ADS::BuddyAllocator::BuddyAllocator
BuddyAllocator(int m)
the memory of words, one free block
ADS::BuddyAllocator::freeWords
long freeWords(void) const
the number of the words in free blocks
ADS
Definition
ADT.h:96
ADS
memory
Allocators.h
Generated by
1.17.0