| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 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 {}
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition: AllocatorPool.h:108
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:109

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

Destructor. Return storage to the free store.

Definition at line 84 of file AllocatorPool.cpp.

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

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

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

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

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 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:111
GaudiUtils::AllocatorPool::esize
const unsigned int esize
Definition: AllocatorPool.h:108
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:217
IOTest.start
start
Definition: IOTest.py:88
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:110
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:112
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:109

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 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:111
std::right
T right(T...args)
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:110
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:112

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 }
GaudiUtils::AllocatorPool::head
PoolLink * head
Definition: AllocatorPool.h:111
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:217
GaudiUtils::AllocatorPool::chunks
PoolChunk * chunks
Definition: AllocatorPool.h:110
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:112

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

Return storage size.

Definition at line 149 of file AllocatorPool.h.

150 {
151 return nchunks*csize;
152 }
GaudiUtils::AllocatorPool::nchunks
int nchunks
Definition: AllocatorPool.h:112
GaudiUtils::AllocatorPool::csize
const unsigned int csize
Definition: AllocatorPool.h:109

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

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