| The Gaudi Framework v32r1 (f65d50dc)

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