Gaudi Framework, version v21r8

Home   Generated: 17 Mar 2010

GaudiUtils::AllocatorPool Class Reference

Allocator pool. More...

#include <GaudiKernel/AllocatorPool.h>

Collaboration diagram for GaudiUtils::AllocatorPool:

Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Private Member Functions

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

Private Attributes

const unsigned int esize
const unsigned int csize
PoolChunkchunks
PoolLinkhead
int nchunks

Classes

class  PoolChunk
struct  PoolLink


Detailed Description

Allocator pool.

Class is imported from Geant4 project

Date:
2006-02-14

Definition at line 65 of file AllocatorPool.h.


Constructor & Destructor Documentation

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

Create a pool of elements of size n.

Definition at line 53 of file AllocatorPool.cpp.

00054   : esize(sz<sizeof(PoolLink) ? sizeof(PoolLink) : sz),
00055     csize(sz<1024/2-16 ? 1024-16 : sz*10-16),
00056     chunks(0), head(0), nchunks(0)
00057 {}

GaudiUtils::AllocatorPool::~AllocatorPool (  ) 

Destructor. Return storage to the free store.

Definition at line 88 of file AllocatorPool.cpp.

00089 {
00090   Reset();
00091 }

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

Copy constructor.

Definition at line 63 of file AllocatorPool.cpp.

00064   : esize(right.esize), csize(right.csize)
00065 {
00066   *this = right;
00067 } 


Member Function Documentation

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

Allocate one element.

Definition at line 127 of file AllocatorPool.h.

00128 {
00129   if ( head==0 ) { Grow(); }
00130   PoolLink* p = head;  // return first element
00131   head = p->next;
00132   return p;
00133 }

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

Return an element back to the pool.

Definition at line 140 of file AllocatorPool.h.

00141 {
00142   PoolLink* p = static_cast<PoolLink*>(b);
00143   p->next = head;        // put b back as first element
00144   head = p;
00145 }

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

Return storage size.

Definition at line 152 of file AllocatorPool.h.

00153 {
00154   return nchunks*csize;
00155 }

void GaudiUtils::AllocatorPool::Reset ( void   ) 

Return storage to the free store.

Definition at line 97 of file AllocatorPool.cpp.

00098 {
00099   // Free all chunks
00100   //
00101   PoolChunk* n = chunks;
00102   PoolChunk* p = 0;
00103   while (n)
00104   {
00105     p = n;
00106     n = n->next;
00107     delete p;
00108   }
00109   head = 0;
00110   chunks = 0;
00111   nchunks = 0;
00112 }

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

Private equality operator.

Definition at line 75 of file AllocatorPool.cpp.

00076 {
00077   if (&right == this) { return *this; }
00078   chunks  = right.chunks;
00079   head    = right.head;
00080   nchunks = right.nchunks;
00081   return *this;
00082 }

void GaudiUtils::AllocatorPool::Grow (  )  [private]

Make pool larger.

Definition at line 118 of file AllocatorPool.cpp.

00119 {
00120   // Allocate new chunk, organize it as a linked list of
00121   // elements of size 'esize'
00122   //
00123   PoolChunk* n = new PoolChunk(csize);
00124   n->next = chunks;
00125   chunks = n;
00126   nchunks++;
00127   
00128   const int nelem = csize/esize;
00129   char* start = n->mem;
00130   char* last = &start[(nelem-1)*esize];
00131   for (char* p=start; p<last; p+=esize)
00132   {
00133     reinterpret_cast<PoolLink*>(p)->next
00134       = reinterpret_cast<PoolLink*>(p+esize);
00135   }
00136   reinterpret_cast<PoolLink*>(last)->next = 0;
00137   head = reinterpret_cast<PoolLink*>(start);
00138 }


Member Data Documentation

const unsigned int GaudiUtils::AllocatorPool::esize [private]

Definition at line 111 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::csize [private]

Definition at line 112 of file AllocatorPool.h.

Definition at line 113 of file AllocatorPool.h.

Definition at line 114 of file AllocatorPool.h.

Definition at line 115 of file AllocatorPool.h.


The documentation for this class was generated from the following files:

Generated at Wed Mar 17 18:22:00 2010 for Gaudi Framework, version v21r8 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004