| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Classes | Public Member Functions | Private Member Functions | Private Attributes

# GaudiUtils::AllocatorPool Class Reference

Allocator pool. More...

`#include <GaudiKernel/AllocatorPool.h>`

Collaboration diagram for GaudiUtils::AllocatorPool:
[legend]

List of all members.

## Classes
class | PoolChunk
struct | PoolLink
## Public Member Functions
| AllocatorPool (unsigned int n=0)
| Create a pool of elements of size n.
| ~AllocatorPool ()
| Destructor. Return storage to the free store.
| AllocatorPool (const AllocatorPool &right)
| Copy constructor.
void * | Alloc ()
| Allocate one element.
void | Free (void *b)
| Return an element back to the pool.
unsigned int | Size () const
| Return storage size.
void | Reset ()
| Return storage to the free store.
## Private Member Functions
AllocatorPool & | operator= (const AllocatorPool &right)
| Private equality operator.
void | Grow ()
| Make pool larger.
## Private Attributes
const unsigned int | esize
const unsigned int | csize
PoolChunk * | chunks
PoolLink * | head
int | nchunks

## Detailed Description

Allocator pool.

Class is imported from Geant4 project

Date:
  2006-02-14

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

      : esize(sz<sizeof(PoolLink) ? sizeof(PoolLink) : sz),
        csize(sz<1024/2-16 ? 1024-16 : sz*10-16),
        chunks(0), head(0), nchunks(0)
    {}

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

Destructor. Return storage to the free store.

Definition at line 88 of file AllocatorPool.cpp.

    {
      Reset();
    }

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

Copy constructor.

Definition at line 63 of file AllocatorPool.cpp.

      : esize(right.esize), csize(right.csize)
    {
      *this = right;
    }

## Member Function Documentation

void * GaudiUtils::AllocatorPool::Alloc | ( | ) | `[inline]`

Allocate one element.

Definition at line 127 of file AllocatorPool.h.

    {
      if ( head==0 ) { Grow(); }
      PoolLink* p = head;  // return first element
      head = p->next;
      return p;
    }

void GaudiUtils::AllocatorPool::Free | ( | void * | b ) | `[inline]`

Return an element back to the pool.

Definition at line 140 of file AllocatorPool.h.

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

void GaudiUtils::AllocatorPool::Grow | ( | ) | `[private]`

Make pool larger.

Definition at line 118 of file AllocatorPool.cpp.

    {
      // Allocate new chunk, organize it as a linked list of
      // elements of size 'esize'
      //
      PoolChunk* n = new PoolChunk(csize);
      n->next = chunks;
      chunks = n;
      nchunks++;

      const int nelem = csize/esize;
      char* start = n->mem;
      char* last = &start[(nelem-1)*esize];
      for (char* p=start; p<last; p+=esize)
      {
        reinterpret_cast<PoolLink*>(p)->next
          = reinterpret_cast<PoolLink*>(p+esize);
      }
      reinterpret_cast<PoolLink*>(last)->next = 0;
      head = reinterpret_cast<PoolLink*>(start);
    }

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

Private equality operator.

Definition at line 75 of file AllocatorPool.cpp.

    {
      if (&right == this) { return *this; }
      chunks  = right.chunks;
      head    = right.head;
      nchunks = right.nchunks;
      return *this;
    }

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

Return storage to the free store.

Definition at line 97 of file AllocatorPool.cpp.

    {
      // Free all chunks
      //
      PoolChunk* n = chunks;
      PoolChunk* p = 0;
      while (n)
      {
        p = n;
        n = n->next;
        delete p;
      }
      head = 0;
      chunks = 0;
      nchunks = 0;
    }

unsigned int GaudiUtils::AllocatorPool::Size | ( | ) | const`[inline]`

Return storage size.

Definition at line 152 of file AllocatorPool.h.

    {
      return nchunks*csize;
    }

## Member Data Documentation

PoolChunk* GaudiUtils::AllocatorPool::chunks`[private]`

Definition at line 113 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::csize`[private]`

Definition at line 112 of file AllocatorPool.h.

const unsigned int GaudiUtils::AllocatorPool::esize`[private]`

Definition at line 111 of file AllocatorPool.h.

PoolLink* GaudiUtils::AllocatorPool::head`[private]`

Definition at line 114 of file AllocatorPool.h.

int GaudiUtils::AllocatorPool::nchunks`[private]`

Definition at line 115 of file AllocatorPool.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/GaudiKernel/GaudiKernel/AllocatorPool.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/GaudiKernel/src/Lib/AllocatorPool.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines