The Gaudi Framework  master (37c0b60a)
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 72 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 59 of file AllocatorPool.cpp.

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

◆ ~AllocatorPool()

GaudiUtils::AllocatorPool::~AllocatorPool ( )

Destructor. Return storage to the free store.

Definition at line 87 of file AllocatorPool.cpp.

87 { Reset(); }

◆ AllocatorPool() [2/2]

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

Copy constructor.

Definition at line 67 of file AllocatorPool.cpp.

67  : esize( right.esize ), csize( right.csize ) {
68  *this = right;
69 }

Member Function Documentation

◆ Alloc()

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

Allocate one element.

Definition at line 122 of file AllocatorPool.h.

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

◆ Free()

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

Return an element back to the pool.

Definition at line 133 of file AllocatorPool.h.

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

◆ Grow()

void GaudiUtils::AllocatorPool::Grow ( )
private

Make pool larger.

Definition at line 112 of file AllocatorPool.cpp.

112  {
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 }

◆ operator=()

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

Private equality operator.

Definition at line 75 of file AllocatorPool.cpp.

75  {
76  if ( &right == this ) { return *this; }
77  chunks = right.chunks;
78  head = right.head;
79  nchunks = right.nchunks;
80  return *this;
81 }

◆ Reset()

void GaudiUtils::AllocatorPool::Reset ( )

Return storage to the free store.

Definition at line 93 of file AllocatorPool.cpp.

93  {
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 }

◆ Size()

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

Return storage size.

Definition at line 143 of file AllocatorPool.h.

143 { return nchunks * csize; }

Member Data Documentation

◆ chunks

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

Definition at line 111 of file AllocatorPool.h.

◆ csize

const unsigned int GaudiUtils::AllocatorPool::csize
private

Definition at line 110 of file AllocatorPool.h.

◆ esize

const unsigned int GaudiUtils::AllocatorPool::esize
private

Definition at line 109 of file AllocatorPool.h.

◆ head

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

Definition at line 112 of file AllocatorPool.h.

◆ nchunks

int GaudiUtils::AllocatorPool::nchunks = 0
private

Definition at line 113 of file AllocatorPool.h.


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