Loading [MathJax]/jax/output/HTML-CSS/config.js
The Gaudi Framework  v28r2p1 (f1a77ff4)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiUtils::AllocatorPool Class Referencefinal

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 = nullptr
 
PoolLinkhead = nullptr
 
int nchunks = 0
 

Detailed Description

Allocator pool.

Class is imported from Geant4 project

Date
2006-02-14

Definition at line 63 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 50 of file AllocatorPool.cpp.

51  : esize(sz<sizeof(PoolLink) ? sizeof(PoolLink) : sz),
52  csize(sz<1024/2-16 ? 1024-16 : sz*10-16)
53 {}
const unsigned int esize
const unsigned int csize
GaudiUtils::AllocatorPool::~AllocatorPool ( )

Destructor. Return storage to the free store.

Definition at line 84 of file AllocatorPool.cpp.

85 {
86  Reset();
87 }
void Reset()
Return storage to the free store.
GaudiUtils::AllocatorPool::AllocatorPool ( const AllocatorPool right)

Copy constructor.

Definition at line 59 of file AllocatorPool.cpp.

60  : esize(right.esize), csize(right.csize)
61 {
62  *this = right;
63 }
T right(T...args)
const unsigned int esize
const unsigned int csize

Member Function Documentation

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

Allocate one element.

Definition at line 124 of file AllocatorPool.h.

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

Return an element back to the pool.

Definition at line 137 of file AllocatorPool.h.

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

Make pool larger.

Definition at line 114 of file AllocatorPool.cpp.

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

Private equality operator.

Definition at line 71 of file AllocatorPool.cpp.

72 {
73  if (&right == this) { return *this; }
74  chunks = right.chunks;
75  head = right.head;
76  nchunks = right.nchunks;
77  return *this;
78 }
T right(T...args)
void GaudiUtils::AllocatorPool::Reset ( )

Return storage to the free store.

Definition at line 93 of file AllocatorPool.cpp.

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

Return storage size.

Definition at line 149 of file AllocatorPool.h.

150 {
151  return nchunks*csize;
152 }
const unsigned int csize

Member Data Documentation

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

Definition at line 110 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::csize
private

Definition at line 109 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::esize
private

Definition at line 108 of file AllocatorPool.h.

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

Definition at line 111 of file AllocatorPool.h.

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: