Geant4
10.02.p03
G4AllocatorPool.cc
Go to the documentation of this file.
1
//
2
// ********************************************************************
3
// * License and Disclaimer *
4
// * *
5
// * The Geant4 software is copyright of the Copyright Holders of *
6
// * the Geant4 Collaboration. It is provided under the terms and *
7
// * conditions of the Geant4 Software License, included in the file *
8
// * LICENSE and available at http://cern.ch/geant4/license . These *
9
// * include a list of copyright holders. *
10
// * *
11
// * Neither the authors of this software system, nor their employing *
12
// * institutes,nor the agencies providing financial support for this *
13
// * work make any representation or warranty, express or implied, *
14
// * regarding this software system or assume any liability for its *
15
// * use. Please see the license in the file LICENSE and URL above *
16
// * for the full disclaimer and the limitation of liability. *
17
// * *
18
// * This code implementation is the result of the scientific and *
19
// * technical work of the GEANT4 collaboration. *
20
// * By using, copying, modifying or distributing the software (or *
21
// * any work based on the software) you agree to acknowledge its *
22
// * use in resulting scientific publications, and indicate your *
23
// * acceptance of all terms of the Geant4 Software license. *
24
// ********************************************************************
25
//
26
//
27
// $Id: G4AllocatorPool.cc 67970 2013-03-13 10:10:06Z gcosmo $
28
//
29
//
30
// ----------------------------------------------------------------------
31
// G4AllocatorPool
32
//
33
// Implementation file
34
//
35
// Author: G.Cosmo, November 2000
36
//
37
38
#include "
G4AllocatorPool.hh
"
39
40
// ************************************************************
41
// G4AllocatorPool constructor
42
// ************************************************************
43
//
44
G4AllocatorPool::G4AllocatorPool
(
unsigned
int
sz )
45
: esize(sz<sizeof(
G4PoolLink
) ? sizeof(
G4PoolLink
) : sz),
46
csize(sz<1024/2-16 ? 1024-16 : sz*10-16),
47
chunks(0), head(0), nchunks(0)
48
{
49
}
50
51
// ************************************************************
52
// G4AllocatorPool copy constructor
53
// ************************************************************
54
//
55
G4AllocatorPool::G4AllocatorPool
(
const
G4AllocatorPool
&
right
)
56
:
esize
(right.
esize
),
csize
(right.
csize
),
57
chunks
(right.
chunks
),
head
(right.
head
),
nchunks
(right.
nchunks
)
58
{
59
}
60
61
// ************************************************************
62
// G4AllocatorPool operator=
63
// ************************************************************
64
//
65
G4AllocatorPool
&
66
G4AllocatorPool::operator=
(
const
G4AllocatorPool
&
right
)
67
{
68
if
(&right ==
this
) {
return
*
this
; }
69
chunks
= right.
chunks
;
70
head
= right.
head
;
71
nchunks
= right.
nchunks
;
72
return
*
this
;
73
}
74
75
// ************************************************************
76
// G4AllocatorPool destructor
77
// ************************************************************
78
//
79
G4AllocatorPool::~G4AllocatorPool
()
80
{
81
Reset
();
82
}
83
84
// ************************************************************
85
// Reset
86
// ************************************************************
87
//
88
void
G4AllocatorPool::Reset
()
89
{
90
// Free all chunks
91
//
92
G4PoolChunk
*
n
=
chunks
;
93
G4PoolChunk
* p = 0;
94
while
(n)
95
{
96
p =
n
;
97
n = n->
next
;
98
delete
p;
99
}
100
head
= 0;
101
chunks
= 0;
102
nchunks
= 0;
103
}
104
105
// ************************************************************
106
// Grow
107
// ************************************************************
108
//
109
void
G4AllocatorPool::Grow
()
110
{
111
// Allocate new chunk, organize it as a linked list of
112
// elements of size 'esize'
113
//
114
G4PoolChunk
*
n
=
new
G4PoolChunk
(
csize
);
115
n->
next
=
chunks
;
116
chunks
=
n
;
117
nchunks
++;
118
119
const
int
nelem =
csize
/
esize
;
120
char
* start = n->
mem
;
121
char
* last = &start[(nelem-1)*
esize
];
122
for
(
char
* p=start; p<last; p+=
esize
)
123
{
124
reinterpret_cast<
G4PoolLink
*
>
(p)->next
125
= reinterpret_cast<G4PoolLink*>(p+
esize
);
126
}
127
reinterpret_cast<
G4PoolLink
*
>
(last)->next = 0;
128
head
=
reinterpret_cast<
G4PoolLink
*
>
(start);
129
}
G4AllocatorPool::esize
const unsigned int esize
Definition:
G4AllocatorPool.hh:103
right
Definition:
F04UserTrackInformation.hh:37
G4AllocatorPool::G4PoolChunk
Definition:
G4AllocatorPool.hh:87
G4AllocatorPool::G4PoolChunk::mem
char * mem
Definition:
G4AllocatorPool.hh:94
G4AllocatorPool::chunks
G4PoolChunk * chunks
Definition:
G4AllocatorPool.hh:105
G4AllocatorPool::Grow
void Grow()
Definition:
G4AllocatorPool.cc:109
G4AllocatorPool::Reset
void Reset()
Definition:
G4AllocatorPool.cc:88
G4AllocatorPool.hh
G4AllocatorPool::operator=
G4AllocatorPool & operator=(const G4AllocatorPool &right)
Definition:
G4AllocatorPool.cc:66
G4AllocatorPool::G4AllocatorPool
G4AllocatorPool(unsigned int n=0)
Definition:
G4AllocatorPool.cc:44
n
Char_t n[5]
Definition:
comparison_ascii.C:55
G4AllocatorPool::~G4AllocatorPool
~G4AllocatorPool()
Definition:
G4AllocatorPool.cc:79
G4AllocatorPool::G4PoolLink
Definition:
G4AllocatorPool.hh:83
G4AllocatorPool::G4PoolChunk::next
G4PoolChunk * next
Definition:
G4AllocatorPool.hh:95
G4AllocatorPool::nchunks
int nchunks
Definition:
G4AllocatorPool.hh:107
G4AllocatorPool::head
G4PoolLink * head
Definition:
G4AllocatorPool.hh:106
G4AllocatorPool::csize
unsigned int csize
Definition:
G4AllocatorPool.hh:104
G4AllocatorPool
Definition:
G4AllocatorPool.hh:50
Geant4
Geant4.10.02.p03
source
global
management
src
G4AllocatorPool.cc
Generated by
1.8.13