The Gaudi Framework
v25r3
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
AllocatorPool.h
Go to the documentation of this file.
1
// $Id: AllocatorPool.h,v 1.3 2007/05/24 14:39:11 hmd Exp $
2
// ============================================================================
3
// CVS tag $Name: $, version $Revision: 1.3 $
4
// ============================================================================
10
// ============================================================================
11
12
//
13
// ********************************************************************
14
// * DISCLAIMER *
15
// * *
16
// * The following disclaimer summarizes all the specific disclaimers *
17
// * of contributors to this software. The specific disclaimers,which *
18
// * govern, are listed with their locations in: *
19
// * http://cern.ch/geant4/license *
20
// * *
21
// * Neither the authors of this software system, nor their employing *
22
// * institutes,nor the agencies providing financial support for this *
23
// * work make any representation or warranty, express or implied, *
24
// * regarding this software system or assume any liability for its *
25
// * use. *
26
// * *
27
// * This code implementation is the intellectual property of the *
28
// * GEANT4 collaboration. *
29
// * By copying, distributing or modifying the Program (or any work *
30
// * based on the Program) you indicate your acceptance of this *
31
// * statement, and all its terms. *
32
// ********************************************************************
33
//
34
// -------------------------------------------------------------------
35
// GEANT 4 class header file
36
//
37
// Class description:
38
//
39
// Class implementing a memory pool for fast allocation and deallocation
40
// of memory chunks. The size of the chunks for small allocated objects
41
// is fixed to 1Kb and takes into account of memory alignment; for large
42
// objects it is set to 10 times the object's size.
43
// The implementation is derived from: B.Stroustrup, The C++ Programming
44
// Language, Third Edition.
45
46
// -------------- G4AllocatorPool ----------------
47
//
48
// Author: G.Cosmo (CERN), November 2000
49
// -------------------------------------------------------------------
50
51
#ifndef GAUDIKERNEL_AllocatorPool_h
52
#define GAUDIKERNEL_AllocatorPool_h 1
53
54
#include "
GaudiKernel/Kernel.h
"
55
56
namespace
GaudiUtils
57
{
65
class
GAUDI_API
AllocatorPool
66
{
67
public
:
68
70
explicit
AllocatorPool
(
unsigned
int
n
=0 );
72
~
AllocatorPool
();
74
AllocatorPool
(
const
AllocatorPool
& right);
76
inline
void
* Alloc();
78
inline
void
Free(
void
* b );
80
inline
unsigned
int
Size()
const
;
82
void
Reset();
83
84
private
:
85
87
AllocatorPool
& operator= (
const
AllocatorPool
& right);
88
89
private
:
90
91
struct
PoolLink
92
{
93
PoolLink
*
next
;
94
};
95
class
PoolChunk
96
{
97
public
:
98
explicit
PoolChunk
(
unsigned
int
sz)
99
: size(sz), mem(new char[size]), next(0) {;}
100
~PoolChunk
() {
delete
[] mem; }
101
const
unsigned
int
size
;
102
char
*
mem
;
103
PoolChunk
*
next
;
104
};
105
107
void
Grow();
108
109
private
:
110
111
const
unsigned
int
esize
;
112
const
unsigned
int
csize
;
113
PoolChunk
*
chunks
;
114
PoolLink
*
head
;
115
int
nchunks
;
116
};
117
118
}
// end of namespace GaudiUtils
119
120
121
122
// ************************************************************
123
// Alloc
124
// ************************************************************
125
//
126
inline
void
*
127
GaudiUtils::AllocatorPool::Alloc
()
128
{
129
if
(
head
==0 ) {
Grow
(); }
130
PoolLink
* p =
head
;
// return first element
131
head
= p->
next
;
132
return
p;
133
}
134
135
// ************************************************************
136
// Free
137
// ************************************************************
138
//
139
inline
void
140
GaudiUtils::AllocatorPool::Free
(
void
* b )
141
{
142
PoolLink
* p =
static_cast<
PoolLink
*
>
(b);
143
p->
next
= head;
// put b back as first element
144
head = p;
145
}
146
147
// ************************************************************
148
// Size
149
// ************************************************************
150
//
151
inline
unsigned
int
152
GaudiUtils::AllocatorPool::Size
()
const
153
{
154
return
nchunks*csize;
155
}
156
157
158
// ============================================================================
159
// The END
160
// ============================================================================
161
#endif
162
// ============================================================================
163
Kernel.h
GaudiUtils::AllocatorPool::PoolChunk
Definition:
AllocatorPool.h:95
GaudiUtils::AllocatorPool::PoolLink
Definition:
AllocatorPool.h:91
GaudiUtils::AllocatorPool::PoolChunk::~PoolChunk
~PoolChunk()
Definition:
AllocatorPool.h:100
GaudiUtils::AllocatorPool::Grow
void Grow()
Make pool larger.
Definition:
AllocatorPool.cpp:118
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition:
AllocatorPool.h:114
GaudiUtils::AllocatorPool::Size
unsigned int Size() const
Return storage size.
Definition:
AllocatorPool.h:152
GaudiUtils::AllocatorPool::PoolChunk::mem
char * mem
Definition:
AllocatorPool.h:102
GaudiUtils::AllocatorPool::PoolChunk::next
PoolChunk * next
Definition:
AllocatorPool.h:103
GaudiUtils::AllocatorPool::PoolChunk::PoolChunk
PoolChunk(unsigned int sz)
Definition:
AllocatorPool.h:98
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition:
AllocatorPool.h:111
GaudiUtils::AllocatorPool::PoolChunk::size
const unsigned int size
Definition:
AllocatorPool.h:101
GaudiPluginService.cpluginsvc.n
list n
Definition:
cpluginsvc.py:217
GaudiUtils::AllocatorPool::Alloc
void * Alloc()
Allocate one element.
Definition:
AllocatorPool.h:127
GaudiUtils::AllocatorPool::PoolLink::next
PoolLink * next
Definition:
AllocatorPool.h:93
GaudiUtils::AllocatorPool::Free
void Free(void *b)
Return an element back to the pool.
Definition:
AllocatorPool.h:140
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition:
AllocatorPool.h:113
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition:
AllocatorPool.h:115
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition:
AllocatorPool.h:112
GAUDI_API
#define GAUDI_API
Definition:
Kernel.h:108
GaudiUtils::AllocatorPool
Allocator pool.
Definition:
AllocatorPool.h:65
GaudiKernel
GaudiKernel
AllocatorPool.h
Generated on Wed Jul 9 2014 09:54:13 for The Gaudi Framework by
1.8.7