| The Gaudi Framework v29r1 (5cd95fa2)

- 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( unsigned int sz )
50 : esize( sz < sizeof( PoolLink ) ? sizeof( PoolLink ) : sz ), csize( sz < 1024 / 2 - 16 ? 1024 - 16 : sz * 10 - 16 )
51 {
52 }
53
54 // ************************************************************
55 // G4AllocatorPool copy constructor
56 // ************************************************************
57 //
58 GaudiUtils::AllocatorPool::AllocatorPool( const AllocatorPool& right ) : esize( right.esize ), csize( right.csize )
59 {
60 *this = right;
61 }
62
63 // ************************************************************
64 // G4AllocatorPool operator=
65 // ************************************************************
66 //
67 GaudiUtils::AllocatorPool& GaudiUtils::AllocatorPool::operator=( const GaudiUtils::AllocatorPool& right )
68 {
69 if ( &right == this ) {
70 return *this;
71 }
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 {
90 // Free all chunks
91 //
92 PoolChunk* n = chunks;
93 PoolChunk* p = nullptr;
94 while ( n ) {
95 p = n;
96 n = n->next;
97 delete p;
98 }
99 head = nullptr;
100 chunks = nullptr;
101 nchunks = 0;
102 }
103
104 // ************************************************************
105 // Grow
106 // ************************************************************
107 //
108 void GaudiUtils::AllocatorPool::Grow()
109 {
110 // Allocate new chunk, organize it as a linked list of
111 // elements of size 'esize'
112 //
113 auto n = new PoolChunk( csize );
114 n->next = chunks;
115 chunks = n;
116 ++nchunks;
117
118 const int nelem = csize / esize;
119 char* start = n->mem.get();
120 char* last = &start[( nelem - 1 ) * esize];
121 for ( char* p = start; p < last; p += esize ) {
122 reinterpret_cast<PoolLink*>( p )->next = reinterpret_cast<PoolLink*>( p + esize );
123 }
124 reinterpret_cast<PoolLink*>( last )->next = nullptr;
125 head = reinterpret_cast<PoolLink*>( start );
126 }
127
128 // ============================================================================
129 // The END
130 // ============================================================================
GaudiUtils::AllocatorPool::PoolChunk
Definition: AllocatorPool.h:89
GaudiUtils::AllocatorPool::PoolLink
Definition: AllocatorPool.h:86
GaudiUtils::AllocatorPool::Grow
void Grow()
Make pool larger.
Definition: AllocatorPool.cpp:108
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:105
GaudiUtils::AllocatorPool::operator=
AllocatorPool & operator=(const AllocatorPool &right)
Private equality operator.
Definition: AllocatorPool.cpp:67
GaudiUtils::AllocatorPool::~AllocatorPool
~AllocatorPool()
Destructor. Return storage to the free store.
Definition: AllocatorPool.cpp:82
GaudiUtils::AllocatorPool::PoolChunk::next
PoolChunk * next
Definition: AllocatorPool.h:95
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition: AllocatorPool.h:102
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:228
GaudiUtils::AllocatorPool::Reset
void Reset()
Return storage to the free store.
Definition: AllocatorPool.cpp:88
IOTest.start
start
Definition: IOTest.py:99
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:104
AllocatorPool.h
Allocator pool.
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:106
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:103
GaudiUtils::AllocatorPool::AllocatorPool
AllocatorPool(unsigned int n=0)
Create a pool of elements of size n.
Definition: AllocatorPool.cpp:49
GaudiUtils::AllocatorPool
Allocator pool.
Definition: AllocatorPool.h:63