| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

AllocatorPool.cpp
Go to the documentation of this file.
1 // ============================================================================
7 // ============================================================================
8 //
9 // ********************************************************************
10 // * DISCLAIMER *
11 // * *
12 // * The following disclaimer summarizes all the specific disclaimers *
13 // * of contributors to this software. The specific disclaimers,which *
14 // * govern, are listed with their locations in: *
15 // * http://cern.ch/geant4/license *
16 // * *
17 // * Neither the authors of this software system, nor their employing *
18 // * institutes,nor the agencies providing financial support for this *
19 // * work make any representation or warranty, express or implied, *
20 // * regarding this software system or assume any liability for its *
21 // * use. *
22 // * *
23 // * This code implementation is the intellectual property of the *
24 // * GEANT4 collaboration. *
25 // * By copying, distributing or modifying the Program (or any work *
26 // * based on the Program) you indicate your acceptance of this *
27 // * statement, and all its terms. *
28 // ********************************************************************
29 //
30 // ----------------------------------------------------------------------
31 // G4AllocatorPool
32 //
33 // Implementation file
34 //
35 // Author: G.Cosmo, November 2000
36 //
37 // ============================================================================
38 // Include files
39 // ============================================================================
40 // GaudiKernel
41 // ============================================================================
42 #include "GaudiKernel/AllocatorPool.h"
43 // ============================================================================
44
45 // ************************************************************
46 // G4AllocatorPool constructor
47 // ************************************************************
48 //
49 GaudiUtils::AllocatorPool::AllocatorPool
50 ( unsigned int sz )
51 : esize(sz<sizeof(PoolLink) ? sizeof(PoolLink) : sz),
52 csize(sz<1024/2-16 ? 1024-16 : sz*10-16)
53 {}
54
55 // ************************************************************
56 // G4AllocatorPool copy constructor
57 // ************************************************************
58 //
59 GaudiUtils::AllocatorPool::AllocatorPool(const AllocatorPool& right)
60 : esize(right.esize), csize(right.csize)
61 {
62 *this = right;
63 }
64
65 // ************************************************************
66 // G4AllocatorPool operator=
67 // ************************************************************
68 //
69 GaudiUtils::AllocatorPool&
70 GaudiUtils::AllocatorPool::operator=
71 (const GaudiUtils::AllocatorPool& right)
72 {
73 if (&right == this) { return *this; }
74 chunks = right.chunks;
75 head = right.head;
76 nchunks = right.nchunks;
77 return *this;
78 }
79
80 // ************************************************************
81 // G4AllocatorPool destructor
82 // ************************************************************
83 //
84 GaudiUtils::AllocatorPool::~AllocatorPool()
85 {
86 Reset();
87 }
88
89 // ************************************************************
90 // Reset
91 // ************************************************************
92 //
93 void GaudiUtils::AllocatorPool::Reset()
94 {
95 // Free all chunks
96 //
97 PoolChunk* n = chunks;
98 PoolChunk* p = nullptr;
99 while (n)
100 {
101 p = n;
102 n = n->next;
103 delete p;
104 }
105 head = nullptr;
106 chunks = nullptr;
107 nchunks = 0;
108 }
109
110 // ************************************************************
111 // Grow
112 // ************************************************************
113 //
114 void GaudiUtils::AllocatorPool::Grow()
115 {
116 // Allocate new chunk, organize it as a linked list of
117 // elements of size 'esize'
118 //
119 auto n = new PoolChunk(csize);
120 n->next = chunks;
121 chunks = n;
122 ++nchunks;
123
124 const int nelem = csize/esize;
125 char* start = n->mem.get();
126 char* last = &start[(nelem-1)*esize];
127 for (char* p=start; p<last; p+=esize)
128 {
129 reinterpret_cast<PoolLink*>(p)->next
130 = reinterpret_cast<PoolLink*>(p+esize);
131 }
132 reinterpret_cast<PoolLink*>(last)->next = nullptr;
133 head = reinterpret_cast<PoolLink*>(start);
134 }
135
136
137 // ============================================================================
138 // The END
139 // ============================================================================
GaudiUtils::AllocatorPool::PoolChunk
Definition: AllocatorPool.h:93
GaudiUtils::AllocatorPool::PoolLink
Definition: AllocatorPool.h:89
GaudiUtils::AllocatorPool::Grow
void Grow()
Make pool larger.
Definition: AllocatorPool.cpp:114
GaudiUtils::AllocatorPool::~AllocatorPool
~AllocatorPool()
Destructor. Return storage to the free store.
Definition: AllocatorPool.cpp:84
GaudiUtils::AllocatorPool::PoolChunk::next
PoolChunk * next
Definition: AllocatorPool.h:100
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
GaudiUtils::AllocatorPool::Reset
void Reset()
Return storage to the free store.
Definition: AllocatorPool.cpp:93
AllocatorPool.h
Allocator pool.
GaudiUtils::AllocatorPool::AllocatorPool
AllocatorPool(unsigned int n=0)
Create a pool of elements of size n.
Definition: AllocatorPool.cpp:50
IOTest.start
tuple start
Definition: IOTest.py:88
GaudiUtils::AllocatorPool
Allocator pool.
Definition: AllocatorPool.h:63