The Gaudi Framework
master (01b473db)
AllocatorPool.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
// ============================================================================
17
// ============================================================================
18
//
19
// ********************************************************************
20
// * DISCLAIMER *
21
// * *
22
// * The following disclaimer summarizes all the specific disclaimers *
23
// * of contributors to this software. The specific disclaimers,which *
24
// * govern, are listed with their locations in: *
25
// * http://cern.ch/geant4/license *
26
// * *
27
// * Neither the authors of this software system, nor their employing *
28
// * institutes,nor the agencies providing financial support for this *
29
// * work make any representation or warranty, express or implied, *
30
// * regarding this software system or assume any liability for its *
31
// * use. *
32
// * *
33
// * This code implementation is the intellectual property of the *
34
// * GEANT4 collaboration. *
35
// * By copying, distributing or modifying the Program (or any work *
36
// * based on the Program) you indicate your acceptance of this *
37
// * statement, and all its terms. *
38
// ********************************************************************
39
//
40
// ----------------------------------------------------------------------
41
// G4AllocatorPool
42
//
43
// Implementation file
44
//
45
// Author: G.Cosmo, November 2000
46
//
47
48
#include <
GaudiKernel/AllocatorPool.h
>
49
50
// ************************************************************
51
// G4AllocatorPool constructor
52
// ************************************************************
53
//
54
GaudiUtils::AllocatorPool::AllocatorPool
(
unsigned
int
sz )
55
: esize( sz < sizeof(
PoolLink
) ? sizeof(
PoolLink
) : sz )
56
, csize( sz < 1024 / 2 - 16 ? 1024 - 16 : sz * 10 - 16 ) {}
57
58
// ************************************************************
59
// G4AllocatorPool copy constructor
60
// ************************************************************
61
//
62
GaudiUtils::AllocatorPool::AllocatorPool
(
const
AllocatorPool
& right ) : esize( right.esize ), csize( right.csize ) {
63
*
this
= right;
64
}
65
66
// ************************************************************
67
// G4AllocatorPool operator=
68
// ************************************************************
69
//
70
GaudiUtils::AllocatorPool
&
GaudiUtils::AllocatorPool::operator=
(
const
GaudiUtils::AllocatorPool
& right ) {
71
if
( &right ==
this
) {
return
*
this
; }
72
chunks = right.
chunks
;
73
head = right.
head
;
74
nchunks = right.
nchunks
;
75
return
*
this
;
76
}
77
78
// ************************************************************
79
// G4AllocatorPool destructor
80
// ************************************************************
81
//
82
GaudiUtils::AllocatorPool::~AllocatorPool
() { Reset(); }
83
84
// ************************************************************
85
// Reset
86
// ************************************************************
87
//
88
void
GaudiUtils::AllocatorPool::Reset
() {
89
// Free all chunks
90
//
91
PoolChunk
*
n
= chunks;
92
PoolChunk
* p =
nullptr
;
93
while
(
n
) {
94
p =
n
;
95
n
=
n
->next;
96
delete
p;
97
}
98
head =
nullptr
;
99
chunks =
nullptr
;
100
nchunks = 0;
101
}
102
103
// ************************************************************
104
// Grow
105
// ************************************************************
106
//
107
void
GaudiUtils::AllocatorPool::Grow
() {
108
// Allocate new chunk, organize it as a linked list of
109
// elements of size 'esize'
110
//
111
auto
n
=
new
PoolChunk
( csize );
112
n
->next = chunks;
113
chunks =
n
;
114
++nchunks;
115
116
const
int
nelem = csize / esize;
117
char
*
start
=
n
->mem.get();
118
char
* last = &
start
[( nelem - 1 ) * esize];
119
for
(
char
* p =
start
; p < last; p += esize ) {
120
reinterpret_cast<
PoolLink
*
>
( p )->next =
reinterpret_cast<
PoolLink
*
>
( p + esize );
121
}
122
reinterpret_cast<
PoolLink
*
>
( last )->next =
nullptr
;
123
head =
reinterpret_cast<
PoolLink
*
>
(
start
);
124
}
GaudiUtils::AllocatorPool::operator=
AllocatorPool & operator=(const AllocatorPool &right)
Private equality operator.
Definition:
AllocatorPool.cpp:70
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition:
AllocatorPool.h:111
AllocatorPool.h
IOTest.start
start
Definition:
IOTest.py:110
GaudiUtils::AllocatorPool::~AllocatorPool
~AllocatorPool()
Destructor. Return storage to the free store.
Definition:
AllocatorPool.cpp:82
GaudiUtils::AllocatorPool::Grow
void Grow()
Make pool larger.
Definition:
AllocatorPool.cpp:107
cpluginsvc.n
n
Definition:
cpluginsvc.py:234
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition:
AllocatorPool.h:110
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition:
AllocatorPool.h:112
GaudiUtils::AllocatorPool
Definition:
AllocatorPool.h:71
GaudiUtils::AllocatorPool::AllocatorPool
AllocatorPool(unsigned int n=0)
Create a pool of elements of size n.
Definition:
AllocatorPool.cpp:54
GaudiUtils::AllocatorPool::PoolChunk
Definition:
AllocatorPool.h:96
GaudiUtils::AllocatorPool::Reset
void Reset()
Return storage to the free store.
Definition:
AllocatorPool.cpp:88
GaudiUtils::AllocatorPool::PoolLink
Definition:
AllocatorPool.h:93
GaudiKernel
src
Lib
AllocatorPool.cpp
Generated on Thu Sep 18 2025 16:37:15 for The Gaudi Framework by
1.8.18