All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiUtils::AllocatorPool Class Reference

Allocator pool. More...

#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
 
PoolLinkhead
 
int nchunks
 

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.

54  : esize(sz<sizeof(PoolLink) ? sizeof(PoolLink) : sz),
55  csize(sz<1024/2-16 ? 1024-16 : sz*10-16),
56  chunks(0), head(0), nchunks(0)
57 {}
const unsigned int esize
const unsigned int csize
GaudiUtils::AllocatorPool::~AllocatorPool ( )

Destructor. Return storage to the free store.

Definition at line 88 of file AllocatorPool.cpp.

89 {
90  Reset();
91 }
void Reset()
Return storage to the free store.
GaudiUtils::AllocatorPool::AllocatorPool ( const AllocatorPool right)

Copy constructor.

Definition at line 63 of file AllocatorPool.cpp.

64  : esize(right.esize), csize(right.csize)
65 {
66  *this = right;
67 }
const unsigned int esize
const unsigned int csize

Member Function Documentation

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

Allocate one element.

Definition at line 127 of file AllocatorPool.h.

128 {
129  if ( head==0 ) { Grow(); }
130  PoolLink* p = head; // return first element
131  head = p->next;
132  return p;
133 }
void Grow()
Make pool larger.
void GaudiUtils::AllocatorPool::Free ( void *  b)
inline

Return an element back to the pool.

Definition at line 140 of file AllocatorPool.h.

141 {
142  PoolLink* p = static_cast<PoolLink*>(b);
143  p->next = head; // put b back as first element
144  head = p;
145 }
void GaudiUtils::AllocatorPool::Grow ( )
private

Make pool larger.

Definition at line 118 of file AllocatorPool.cpp.

119 {
120  // Allocate new chunk, organize it as a linked list of
121  // elements of size 'esize'
122  //
123  PoolChunk* n = new PoolChunk(csize);
124  n->next = chunks;
125  chunks = n;
126  nchunks++;
127 
128  const int nelem = csize/esize;
129  char* start = n->mem;
130  char* last = &start[(nelem-1)*esize];
131  for (char* p=start; p<last; p+=esize)
132  {
133  reinterpret_cast<PoolLink*>(p)->next
134  = reinterpret_cast<PoolLink*>(p+esize);
135  }
136  reinterpret_cast<PoolLink*>(last)->next = 0;
137  head = reinterpret_cast<PoolLink*>(start);
138 }
const unsigned int esize
const unsigned int csize
tuple start
Definition: IOTest.py:88
GaudiUtils::AllocatorPool & GaudiUtils::AllocatorPool::operator= ( const AllocatorPool right)
private

Private equality operator.

Definition at line 75 of file AllocatorPool.cpp.

76 {
77  if (&right == this) { return *this; }
78  chunks = right.chunks;
79  head = right.head;
80  nchunks = right.nchunks;
81  return *this;
82 }
void GaudiUtils::AllocatorPool::Reset ( )

Return storage to the free store.

Definition at line 97 of file AllocatorPool.cpp.

98 {
99  // Free all chunks
100  //
101  PoolChunk* n = chunks;
102  PoolChunk* p = 0;
103  while (n)
104  {
105  p = n;
106  n = n->next;
107  delete p;
108  }
109  head = 0;
110  chunks = 0;
111  nchunks = 0;
112 }
unsigned int GaudiUtils::AllocatorPool::Size ( ) const
inline

Return storage size.

Definition at line 152 of file AllocatorPool.h.

153 {
154  return nchunks*csize;
155 }
const unsigned int csize

Member Data Documentation

PoolChunk* GaudiUtils::AllocatorPool::chunks
private

Definition at line 113 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::csize
private

Definition at line 112 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::esize
private

Definition at line 111 of file AllocatorPool.h.

PoolLink* GaudiUtils::AllocatorPool::head
private

Definition at line 114 of file AllocatorPool.h.

int GaudiUtils::AllocatorPool::nchunks
private

Definition at line 115 of file AllocatorPool.h.


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