Loading [MathJax]/jax/output/HTML-CSS/config.js
The Gaudi Framework  v32r2 (46d42edc)
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 62 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 49 of file AllocatorPool.cpp.

50  : esize( sz < sizeof( PoolLink ) ? sizeof( PoolLink ) : sz )
51  , csize( sz < 1024 / 2 - 16 ? 1024 - 16 : sz * 10 - 16 ) {}
const unsigned int esize
Definition: AllocatorPool.h:99
const unsigned int csize

◆ ~AllocatorPool()

GaudiUtils::AllocatorPool::~AllocatorPool ( )

Destructor. Return storage to the free store.

Definition at line 77 of file AllocatorPool.cpp.

77 { Reset(); }
void Reset()
Return storage to the free store.

◆ AllocatorPool() [2/2]

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

Copy constructor.

Definition at line 57 of file AllocatorPool.cpp.

57  : esize( right.esize ), csize( right.csize ) {
58  *this = right;
59 }
T right(T... args)
const unsigned int esize
Definition: AllocatorPool.h:99
const unsigned int csize

Member Function Documentation

◆ Alloc()

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

Allocate one element.

Definition at line 112 of file AllocatorPool.h.

112  {
113  if ( head == 0 ) { Grow(); }
114  PoolLink* p = head; // return first element
115  head = p->next;
116  return p;
117 }
void Grow()
Make pool larger.

◆ Free()

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

Return an element back to the pool.

Definition at line 123 of file AllocatorPool.h.

123  {
124  PoolLink* p = static_cast<PoolLink*>( b );
125  p->next = head; // put b back as first element
126  head = p;
127 }

◆ Grow()

void GaudiUtils::AllocatorPool::Grow ( )
private

Make pool larger.

Definition at line 102 of file AllocatorPool.cpp.

102  {
103  // Allocate new chunk, organize it as a linked list of
104  // elements of size 'esize'
105  //
106  auto n = new PoolChunk( csize );
107  n->next = chunks;
108  chunks = n;
109  ++nchunks;
110 
111  const int nelem = csize / esize;
112  char* start = n->mem.get();
113  char* last = &start[( nelem - 1 ) * esize];
114  for ( char* p = start; p < last; p += esize ) {
115  reinterpret_cast<PoolLink*>( p )->next = reinterpret_cast<PoolLink*>( p + esize );
116  }
117  reinterpret_cast<PoolLink*>( last )->next = nullptr;
118  head = reinterpret_cast<PoolLink*>( start );
119 }
const unsigned int esize
Definition: AllocatorPool.h:99
def start
Definition: IOTest.py:98
const unsigned int csize

◆ operator=()

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

Private equality operator.

Definition at line 65 of file AllocatorPool.cpp.

65  {
66  if ( &right == this ) { return *this; }
67  chunks = right.chunks;
68  head = right.head;
69  nchunks = right.nchunks;
70  return *this;
71 }
T right(T... args)

◆ Reset()

void GaudiUtils::AllocatorPool::Reset ( )

Return storage to the free store.

Definition at line 83 of file AllocatorPool.cpp.

83  {
84  // Free all chunks
85  //
86  PoolChunk* n = chunks;
87  PoolChunk* p = nullptr;
88  while ( n ) {
89  p = n;
90  n = n->next;
91  delete p;
92  }
93  head = nullptr;
94  chunks = nullptr;
95  nchunks = 0;
96 }

◆ Size()

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

Return storage size.

Definition at line 133 of file AllocatorPool.h.

133 { return nchunks * csize; }
const unsigned int csize

Member Data Documentation

◆ chunks

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

Definition at line 101 of file AllocatorPool.h.

◆ csize

const unsigned int GaudiUtils::AllocatorPool::csize
private

Definition at line 100 of file AllocatorPool.h.

◆ esize

const unsigned int GaudiUtils::AllocatorPool::esize
private

Definition at line 99 of file AllocatorPool.h.

◆ head

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

Definition at line 102 of file AllocatorPool.h.

◆ nchunks

int GaudiUtils::AllocatorPool::nchunks = 0
private

Definition at line 103 of file AllocatorPool.h.


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