OPAL (Object Oriented Parallel Accelerator Library)
2.2.0
OPAL
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
ippl
src
Utility
Pool.cpp
Go to the documentation of this file.
1
// -*- C++ -*-
2
/***************************************************************************
3
*
4
* The IPPL Framework
5
*
6
* This program was prepared by PSI.
7
* All rights in the program are reserved by PSI.
8
* Neither PSI nor the author(s)
9
* makes any warranty, express or implied, or assumes any liability or
10
* responsibility for the use of this software
11
*
12
* Visit www.amas.web.psi for more details
13
*
14
***************************************************************************/
15
16
// -*- C++ -*-
17
/***************************************************************************
18
*
19
* The IPPL Framework
20
*
21
*
22
* Visit http://people.web.psi.ch/adelmann/ for more details
23
*
24
***************************************************************************/
25
26
// include files
27
#include "
Utility/Pool.h
"
28
#include "
Utility/PAssert.h
"
29
30
31
#include <cstdlib>
32
33
// Null ctor creates an invalid Pool.
34
Pool::Pool
()
35
: outstandingAllocs(0),
// Number of blocks given to user
36
bsize(0),
// The size of each block
37
nblock(0),
// Number of blocks
38
head(0)
// the first one.
39
{
40
}
41
42
// Make a new Pool for objects of a given size.
43
Pool::Pool
(
size_t
sz)
44
: outstandingAllocs(0),
// Number of blocks given to user
45
bsize(round_to_align(sz)),
// The size of each block
46
nblock(blocks_in_page(bsize)),
// Number of blocks
47
head(0)
// the first one.
48
{
49
}
50
51
// Destroy the Pool.
52
Pool::~Pool
()
53
{
54
PInsist
(
outstandingAllocs
==0,
"Not all of the pooled memory was freed!"
);
55
56
// Loop over the allocated chunks and free them.
57
std::vector<char*>::iterator
p, pend =
chunks
.end();
58
for
(p =
chunks
.begin(); p != pend; ++p)
59
delete
[] *p;
60
}
61
62
// Grow a Pool.
63
void
Pool::grow
()
64
{
65
66
size_t
alloc_this;
67
if
(
bsize
>
page
() )
68
alloc_this =
bsize
;
69
else
70
alloc_this =
page
();
71
72
char
*start =
new
char
[alloc_this];
// Allocate aligned space.
73
chunks
.push_back(start);
// Put it in list of chunks.
74
char
*last = start + (
nblock
-1)*
bsize
;
// Get a pointer to the last one.
75
76
for
(
char
*p=start; p!=last; p+=
bsize
)
// For all but the last one
77
((
Link
*)p)->next = (
Link
*)(p+
bsize
);
// point to the next.
78
((
Link
*)last)->next =
head
;
// The last points to the head
79
head
= (
Link
*)start;
// Reset the head to the first.
80
}
81
82
/***************************************************************************
83
* $RCSfile: Pool.cpp,v $ $Author: adelmann $
84
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
85
* IPPL_VERSION_ID: $Id: Pool.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
86
***************************************************************************/
Pool::head
Link * head
Definition:
Pool.h:84
Pool::bsize
size_t bsize
Definition:
Pool.h:82
Pool::Link
Definition:
Pool.h:21
Pool.h
Pool::grow
void grow()
Definition:
Pool.cpp:63
Pool::chunks
std::vector< char * > chunks
Definition:
Pool.h:85
Pool::outstandingAllocs
int outstandingAllocs
Definition:
Pool.h:81
Pool::~Pool
~Pool()
Definition:
Pool.cpp:52
Pool::Pool
Pool()
Definition:
Pool.cpp:34
mslang::iterator
std::string::iterator iterator
Definition:
MSLang.h:16
PInsist
#define PInsist(c, m)
Definition:
PAssert.h:135
Pool::page
static size_t page()
Definition:
Pool.h:22
Pool::nblock
size_t nblock
Definition:
Pool.h:83
PAssert.h
Generated on Sat Jan 4 2020 14:47:40 for OPAL (Object Oriented Parallel Accelerator Library) by
1.8.5