| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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 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 49 of file AllocatorPool.cpp.

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

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

Destructor. Return storage to the free store.

Definition at line 82 of file AllocatorPool.cpp.

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

GaudiUtils::AllocatorPool::AllocatorPool | ( | const AllocatorPool & | right | ) |

Copy constructor.

Definition at line 58 of file AllocatorPool.cpp.

58 : esize( right.esize ), csize( right.csize )
59 {
60 *this = right;
61 }
std::right
T right(T...args)
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition: AllocatorPool.h:102
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:103

## Member Function Documentation

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

Allocate one element.

Definition at line 115 of file AllocatorPool.h.

116 {
117 if ( head == 0 ) {
118 Grow();
119 }
120 PoolLink* p = head; // return first element
121 head = p->next;
122 return p;
123 }
GaudiUtils::AllocatorPool::Grow
void Grow()
Make pool larger.
Definition: AllocatorPool.cpp:108
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:105
GaudiUtils::AllocatorPool::PoolLink::next
PoolLink * next
Definition: AllocatorPool.h:87

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

Return an element back to the pool.

Definition at line 129 of file AllocatorPool.h.

130 {
131 PoolLink* p = static_cast<PoolLink*>( b );
132 p->next = head; // put b back as first element
133 head = p;
134 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:105

void GaudiUtils::AllocatorPool::Grow | ( |  | ) |
| private

Make pool larger.

Definition at line 108 of file AllocatorPool.cpp.

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

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

Private equality operator.

Definition at line 67 of file AllocatorPool.cpp.

68 {
69 if ( &right == this ) {
70 return *this;
71 }
72 chunks = right.chunks;
73 head = right.head;
74 nchunks = right.nchunks;
75 return *this;
76 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:105
std::right
T right(T...args)
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:104
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:106

void GaudiUtils::AllocatorPool::Reset | ( |  | ) |

Return storage to the free store.

Definition at line 88 of file AllocatorPool.cpp.

89 {
90 // Free all chunks
91 //
92 PoolChunk* n = chunks;
93 PoolChunk* p = nullptr;
94 while ( n ) {
95 p = n;
96 n = n->next;
97 delete p;
98 }
99 head = nullptr;
100 chunks = nullptr;
101 nchunks = 0;
102 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:105
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:228
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:104
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:106

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

Return storage size.

Definition at line 140 of file AllocatorPool.h.

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

## Member Data Documentation

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

Definition at line 104 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::csize
| private

Definition at line 103 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::esize
| private

Definition at line 102 of file AllocatorPool.h.

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

Definition at line 105 of file AllocatorPool.h.

int GaudiUtils::AllocatorPool::nchunks = 0
| private

Definition at line 106 of file AllocatorPool.h.

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

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