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