Gaudi Framework, version v23r5
Home
Generated: Wed Nov 28 2012
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
GaudiKernel
GaudiKernel
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
Generated at Wed Nov 28 2012 12:17:12 for Gaudi Framework, version v23r5 by
Doxygen
version 1.8.2 written by
Dimitri van Heesch
, © 1997-2004