Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 // ============================================================================
43 // ============================================================================
44 
45 // ************************************************************
46 // G4AllocatorPool constructor
47 // ************************************************************
48 //
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 //
58  *this = right;
59 }
60 
61 // ************************************************************
62 // G4AllocatorPool operator=
63 // ************************************************************
64 //
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 //
78 
79 // ************************************************************
80 // Reset
81 // ************************************************************
82 //
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 //
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 // ============================================================================
void Grow()
Make pool larger.
AllocatorPool & operator=(const AllocatorPool &right)
Private equality operator.
~AllocatorPool()
Destructor. Return storage to the free store.
const unsigned int esize
Definition: AllocatorPool.h:99
void Reset()
Return storage to the free store.
start
Definition: IOTest.py:97
Allocator pool.
const unsigned int csize
AllocatorPool(unsigned int n=0)
Create a pool of elements of size n.