Geant4-11
source
global
management
src
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
// G4AllocatorPool class implementation
27
//
28
// Author: G.Cosmo, November 2000
29
// --------------------------------------------------------------------
30
31
#include "
G4AllocatorPool.hh
"
32
33
// ************************************************************
34
// G4AllocatorPool constructor
35
// ************************************************************
36
//
37
G4AllocatorPool::G4AllocatorPool
(
unsigned
int
sz)
38
: esize(sz < sizeof(
G4PoolLink
) ? sizeof(
G4PoolLink
) : sz)
39
, csize(sz < 1024 / 2 - 16 ? 1024 - 16 : sz * 10 - 16)
40
{}
41
42
// ************************************************************
43
// G4AllocatorPool copy constructor
44
// ************************************************************
45
//
46
G4AllocatorPool::G4AllocatorPool
(
const
G4AllocatorPool
& right)
47
: esize(right.esize)
48
, csize(right.csize)
49
, chunks(right.chunks)
50
, head(right.head)
51
, nchunks(right.nchunks)
52
{}
53
54
// ************************************************************
55
// G4AllocatorPool operator=
56
// ************************************************************
57
//
58
G4AllocatorPool
&
G4AllocatorPool::operator=
(
const
G4AllocatorPool
& right)
59
{
60
if
(&right ==
this
)
61
{
62
return
*
this
;
63
}
64
chunks
= right.
chunks
;
65
head
= right.
head
;
66
nchunks
= right.
nchunks
;
67
return
*
this
;
68
}
69
70
// ************************************************************
71
// G4AllocatorPool destructor
72
// ************************************************************
73
//
74
G4AllocatorPool::~G4AllocatorPool
() {
Reset
(); }
75
76
// ************************************************************
77
// Reset
78
// ************************************************************
79
//
80
void
G4AllocatorPool::Reset
()
81
{
82
// Free all chunks
83
//
84
G4PoolChunk
*
n
=
chunks
;
85
G4PoolChunk
* p =
nullptr
;
86
while
(
n
)
87
{
88
p =
n
;
89
n
=
n
->next;
90
delete
p;
91
}
92
head
=
nullptr
;
93
chunks
=
nullptr
;
94
nchunks
= 0;
95
}
96
97
// ************************************************************
98
// Grow
99
// ************************************************************
100
//
101
void
G4AllocatorPool::Grow
()
102
{
103
// Allocate new chunk, organize it as a linked list of
104
// elements of size 'esize'
105
//
106
G4PoolChunk
*
n
=
new
G4PoolChunk
(
csize
);
107
n
->next =
chunks
;
108
chunks
=
n
;
109
++
nchunks
;
110
111
const
int
nelem =
csize
/
esize
;
112
char
* start =
n
->mem;
113
char
* last = &start[(nelem - 1) *
esize
];
114
for
(
char
* p = start; p < last; p +=
esize
)
115
{
116
reinterpret_cast<
G4PoolLink
*
>
(p)->next =
117
reinterpret_cast<
G4PoolLink
*
>
(p +
esize
);
118
}
119
reinterpret_cast<
G4PoolLink
*
>
(last)->next =
nullptr
;
120
head
=
reinterpret_cast<
G4PoolLink
*
>
(start);
121
}
G4AllocatorPool.hh
G4AllocatorPool::G4PoolChunk
Definition:
G4AllocatorPool.hh:80
G4AllocatorPool
Definition:
G4AllocatorPool.hh:45
G4AllocatorPool::esize
const unsigned int esize
Definition:
G4AllocatorPool.hh:99
G4AllocatorPool::head
G4PoolLink * head
Definition:
G4AllocatorPool.hh:102
G4AllocatorPool::operator=
G4AllocatorPool & operator=(const G4AllocatorPool &right)
Definition:
G4AllocatorPool.cc:58
G4AllocatorPool::csize
unsigned int csize
Definition:
G4AllocatorPool.hh:100
G4AllocatorPool::nchunks
int nchunks
Definition:
G4AllocatorPool.hh:103
G4AllocatorPool::G4AllocatorPool
G4AllocatorPool(unsigned int n=0)
Definition:
G4AllocatorPool.cc:37
G4AllocatorPool::Reset
void Reset()
Definition:
G4AllocatorPool.cc:80
G4AllocatorPool::~G4AllocatorPool
~G4AllocatorPool()
Definition:
G4AllocatorPool.cc:74
G4AllocatorPool::Grow
void Grow()
Definition:
G4AllocatorPool.cc:101
G4AllocatorPool::chunks
G4PoolChunk * chunks
Definition:
G4AllocatorPool.hh:101
CLHEP::detail::n
n
Definition:
Ranlux64Engine.cc:90
G4AllocatorPool::G4PoolLink
Definition:
G4AllocatorPool.hh:76
Generated by
1.9.3