| The Gaudi Framework v32r1 (f65d50dc)

Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
GaudiUtils::AllocatorPool Class Referencefinal

Allocator pool. More...

`#include <GaudiKernel/AllocatorPool.h>`

Collaboration diagram for GaudiUtils::AllocatorPool:
[legend]

## 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
AllocatorPool & | operator= (const AllocatorPool &right)
| Private equality operator. More...
void | Grow ()
| Make pool larger. More...

## Private Attributes
const unsigned int | esize
const unsigned int | csize
PoolChunk * | chunks = nullptr
PoolLink * | head = 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 ) {}
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition: AllocatorPool.h:99
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:100

## ◆ ~AllocatorPool()

GaudiUtils::AllocatorPool::~AllocatorPool | ( |  | ) |

Destructor. Return storage to the free store.

Definition at line 77 of file AllocatorPool.cpp.

77 { Reset(); }
GaudiUtils::AllocatorPool::Reset
void Reset()
Return storage to the free store.
Definition: AllocatorPool.cpp:83

## ◆ 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 }
std::right
T right(T... args)
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition: AllocatorPool.h:99
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:100

## 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 }
GaudiUtils::AllocatorPool::Grow
void Grow()
Make pool larger.
Definition: AllocatorPool.cpp:102
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:102
GaudiUtils::AllocatorPool::PoolLink::next
PoolLink * next
Definition: AllocatorPool.h:85

## ◆ 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 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:102

## ◆ 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 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:102
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition: AllocatorPool.h:99
IOTest.start
def start
Definition: IOTest.py:97
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:210
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:101
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:103
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:100

## ◆ 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 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:102
std::right
T right(T... args)
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:101
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:103

## ◆ 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 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:102
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:210
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:101
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:103

## ◆ Size()

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

Return storage size.

Definition at line 133 of file AllocatorPool.h.

133 { return nchunks * csize; }
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:103
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:100

## 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:

- GaudiKernel/GaudiKernel/AllocatorPool.h
- GaudiKernel/src/Lib/AllocatorPool.cpp