The Gaudi Framework  master (01b473db)
GaudiUtils::AllocatorPool Class Referencefinal

#include <GaudiKernel/AllocatorPool.h>

Collaboration diagram for GaudiUtils::AllocatorPool:

Classes

class  PoolChunk
 
struct  PoolLink
 

Public Member Functions

 AllocatorPool (unsigned int n=0)
 Create a pool of elements of size n. More...
 
 ~AllocatorPool ()
 Destructor. Return storage to the free store. More...
 
 AllocatorPool (const AllocatorPool &right)
 Copy constructor. More...
 
void * Alloc ()
 Allocate one element. More...
 
void Free (void *b)
 Return an element back to the pool. More...
 
unsigned int Size () const
 Return storage size. More...
 
void Reset ()
 Return storage to the free store. More...
 

Private Member Functions

AllocatorPooloperator= (const AllocatorPool &right)
 Private equality operator. More...
 
void Grow ()
 Make pool larger. More...
 

Private Attributes

const unsigned int esize
 
const unsigned int csize
 
PoolChunkchunks = nullptr
 
PoolLinkhead = nullptr
 
int nchunks = 0
 

Detailed Description

Allocator pool. Class is imported from Geant4 project

Date
2006-02-14

Definition at line 71 of file AllocatorPool.h.

Constructor & Destructor Documentation

◆ AllocatorPool() [1/2]

GaudiUtils::AllocatorPool::AllocatorPool ( unsigned int  n = 0)
explicit

Create a pool of elements of size n.

Definition at line 54 of file AllocatorPool.cpp.

55  : esize( sz < sizeof( PoolLink ) ? sizeof( PoolLink ) : sz )
56  , csize( sz < 1024 / 2 - 16 ? 1024 - 16 : sz * 10 - 16 ) {}

◆ ~AllocatorPool()

GaudiUtils::AllocatorPool::~AllocatorPool ( )

Destructor. Return storage to the free store.

Definition at line 82 of file AllocatorPool.cpp.

82 { Reset(); }

◆ AllocatorPool() [2/2]

GaudiUtils::AllocatorPool::AllocatorPool ( const AllocatorPool right)

Copy constructor.

Definition at line 62 of file AllocatorPool.cpp.

62  : esize( right.esize ), csize( right.csize ) {
63  *this = right;
64 }

Member Function Documentation

◆ Alloc()

void * GaudiUtils::AllocatorPool::Alloc ( )
inline

Allocate one element.

Definition at line 121 of file AllocatorPool.h.

121  {
122  if ( head == 0 ) { Grow(); }
123  PoolLink* p = head; // return first element
124  head = p->next;
125  return p;
126 }

◆ Free()

void GaudiUtils::AllocatorPool::Free ( void *  b)
inline

Return an element back to the pool.

Definition at line 132 of file AllocatorPool.h.

132  {
133  PoolLink* p = static_cast<PoolLink*>( b );
134  p->next = head; // put b back as first element
135  head = p;
136 }

◆ Grow()

void GaudiUtils::AllocatorPool::Grow ( )
private

Make pool larger.

Definition at line 107 of file AllocatorPool.cpp.

107  {
108  // Allocate new chunk, organize it as a linked list of
109  // elements of size 'esize'
110  //
111  auto n = new PoolChunk( csize );
112  n->next = chunks;
113  chunks = n;
114  ++nchunks;
115 
116  const int nelem = csize / esize;
117  char* start = n->mem.get();
118  char* last = &start[( nelem - 1 ) * esize];
119  for ( char* p = start; p < last; p += esize ) {
120  reinterpret_cast<PoolLink*>( p )->next = reinterpret_cast<PoolLink*>( p + esize );
121  }
122  reinterpret_cast<PoolLink*>( last )->next = nullptr;
123  head = reinterpret_cast<PoolLink*>( start );
124 }

◆ operator=()

GaudiUtils::AllocatorPool & GaudiUtils::AllocatorPool::operator= ( const AllocatorPool right)
private

Private equality operator.

Definition at line 70 of file AllocatorPool.cpp.

70  {
71  if ( &right == this ) { return *this; }
72  chunks = right.chunks;
73  head = right.head;
74  nchunks = right.nchunks;
75  return *this;
76 }

◆ Reset()

void GaudiUtils::AllocatorPool::Reset ( )

Return storage to the free store.

Definition at line 88 of file AllocatorPool.cpp.

88  {
89  // Free all chunks
90  //
91  PoolChunk* n = chunks;
92  PoolChunk* p = nullptr;
93  while ( n ) {
94  p = n;
95  n = n->next;
96  delete p;
97  }
98  head = nullptr;
99  chunks = nullptr;
100  nchunks = 0;
101 }

◆ Size()

unsigned int GaudiUtils::AllocatorPool::Size ( ) const
inline

Return storage size.

Definition at line 142 of file AllocatorPool.h.

142 { return nchunks * csize; }

Member Data Documentation

◆ chunks

PoolChunk* GaudiUtils::AllocatorPool::chunks = nullptr
private

Definition at line 110 of file AllocatorPool.h.

◆ csize

const unsigned int GaudiUtils::AllocatorPool::csize
private

Definition at line 109 of file AllocatorPool.h.

◆ esize

const unsigned int GaudiUtils::AllocatorPool::esize
private

Definition at line 108 of file AllocatorPool.h.

◆ head

PoolLink* GaudiUtils::AllocatorPool::head = nullptr
private

Definition at line 111 of file AllocatorPool.h.

◆ nchunks

int GaudiUtils::AllocatorPool::nchunks = 0
private

Definition at line 112 of file AllocatorPool.h.


The documentation for this class was generated from the following files:
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:111
IOTest.start
start
Definition: IOTest.py:110
GaudiUtils::AllocatorPool::Grow
void Grow()
Make pool larger.
Definition: AllocatorPool.cpp:107
cpluginsvc.n
n
Definition: cpluginsvc.py:234
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:109
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:110
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition: AllocatorPool.h:108
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:112
GaudiUtils::AllocatorPool::Reset
void Reset()
Return storage to the free store.
Definition: AllocatorPool.cpp:88