Geant4  10.02.p03
G4AllocatorPool Class Reference

#include <G4AllocatorPool.hh>

Collaboration diagram for G4AllocatorPool:

Classes

class  G4PoolChunk
 
struct  G4PoolLink
 

Public Member Functions

 G4AllocatorPool (unsigned int n=0)
 
 ~G4AllocatorPool ()
 
void * Alloc ()
 
void Free (void *b)
 
unsigned int Size () const
 
void Reset ()
 
int GetNoPages () const
 
unsigned int GetPageSize () const
 
void GrowPageSize (unsigned int factor)
 

Private Member Functions

 G4AllocatorPool (const G4AllocatorPool &right)
 
G4AllocatorPooloperator= (const G4AllocatorPool &right)
 
void Grow ()
 

Private Attributes

const unsigned int esize
 
unsigned int csize
 
G4PoolChunkchunks
 
G4PoolLinkhead
 
int nchunks
 

Detailed Description

Definition at line 50 of file G4AllocatorPool.hh.

Constructor & Destructor Documentation

◆ G4AllocatorPool() [1/2]

G4AllocatorPool::G4AllocatorPool ( unsigned int  n = 0)
explicit

Definition at line 44 of file G4AllocatorPool.cc.

45  : esize(sz<sizeof(G4PoolLink) ? sizeof(G4PoolLink) : sz),
46  csize(sz<1024/2-16 ? 1024-16 : sz*10-16),
47  chunks(0), head(0), nchunks(0)
48 {
49 }
const unsigned int esize
G4PoolChunk * chunks
G4PoolLink * head
unsigned int csize

◆ ~G4AllocatorPool()

G4AllocatorPool::~G4AllocatorPool ( )

Definition at line 79 of file G4AllocatorPool.cc.

80 {
81  Reset();
82 }
Here is the call graph for this function:

◆ G4AllocatorPool() [2/2]

G4AllocatorPool::G4AllocatorPool ( const G4AllocatorPool right)
private

Definition at line 55 of file G4AllocatorPool.cc.

56  : esize(right.esize), csize(right.csize),
57  chunks(right.chunks), head(right.head), nchunks(right.nchunks)
58 {
59 }
const unsigned int esize
G4PoolChunk * chunks
G4PoolLink * head
unsigned int csize

Member Function Documentation

◆ Alloc()

void * G4AllocatorPool::Alloc ( )
inline

Definition at line 119 of file G4AllocatorPool.hh.

120 {
121  if (head==0) { Grow(); }
122  G4PoolLink* p = head; // return first element
123  head = p->next;
124  return p;
125 }
G4PoolLink * head
Here is the call graph for this function:

◆ Free()

void G4AllocatorPool::Free ( void *  b)
inline

Definition at line 132 of file G4AllocatorPool.hh.

133 {
134  G4PoolLink* p = static_cast<G4PoolLink*>(b);
135  p->next = head; // put b back as first element
136  head = p;
137 }
G4PoolLink * head

◆ GetNoPages()

int G4AllocatorPool::GetNoPages ( ) const
inline

Definition at line 154 of file G4AllocatorPool.hh.

155 {
156  return nchunks;
157 }

◆ GetPageSize()

unsigned int G4AllocatorPool::GetPageSize ( ) const
inline

Definition at line 164 of file G4AllocatorPool.hh.

165 {
166  return csize;
167 }
unsigned int csize

◆ Grow()

void G4AllocatorPool::Grow ( )
private

Definition at line 109 of file G4AllocatorPool.cc.

110 {
111  // Allocate new chunk, organize it as a linked list of
112  // elements of size 'esize'
113  //
114  G4PoolChunk* n = new G4PoolChunk(csize);
115  n->next = chunks;
116  chunks = n;
117  nchunks++;
118 
119  const int nelem = csize/esize;
120  char* start = n->mem;
121  char* last = &start[(nelem-1)*esize];
122  for (char* p=start; p<last; p+=esize)
123  {
124  reinterpret_cast<G4PoolLink*>(p)->next
125  = reinterpret_cast<G4PoolLink*>(p+esize);
126  }
127  reinterpret_cast<G4PoolLink*>(last)->next = 0;
128  head = reinterpret_cast<G4PoolLink*>(start);
129 }
const unsigned int esize
G4PoolChunk * chunks
Char_t n[5]
G4PoolLink * head
unsigned int csize
Here is the caller graph for this function:

◆ GrowPageSize()

void G4AllocatorPool::GrowPageSize ( unsigned int  factor)
inline

Definition at line 174 of file G4AllocatorPool.hh.

175 {
176  csize = (sz) ? sz*csize : csize;
177 }
unsigned int csize

◆ operator=()

G4AllocatorPool & G4AllocatorPool::operator= ( const G4AllocatorPool right)
private

Definition at line 66 of file G4AllocatorPool.cc.

67 {
68  if (&right == this) { return *this; }
69  chunks = right.chunks;
70  head = right.head;
71  nchunks = right.nchunks;
72  return *this;
73 }
G4PoolChunk * chunks
G4PoolLink * head

◆ Reset()

void G4AllocatorPool::Reset ( )

Definition at line 88 of file G4AllocatorPool.cc.

89 {
90  // Free all chunks
91  //
92  G4PoolChunk* n = chunks;
93  G4PoolChunk* p = 0;
94  while (n)
95  {
96  p = n;
97  n = n->next;
98  delete p;
99  }
100  head = 0;
101  chunks = 0;
102  nchunks = 0;
103 }
G4PoolChunk * chunks
Char_t n[5]
G4PoolLink * head
Here is the caller graph for this function:

◆ Size()

unsigned int G4AllocatorPool::Size ( ) const
inline

Definition at line 144 of file G4AllocatorPool.hh.

145 {
146  return nchunks*csize;
147 }
unsigned int csize

Member Data Documentation

◆ chunks

G4PoolChunk* G4AllocatorPool::chunks
private

Definition at line 105 of file G4AllocatorPool.hh.

◆ csize

unsigned int G4AllocatorPool::csize
private

Definition at line 104 of file G4AllocatorPool.hh.

◆ esize

const unsigned int G4AllocatorPool::esize
private

Definition at line 103 of file G4AllocatorPool.hh.

◆ head

G4PoolLink* G4AllocatorPool::head
private

Definition at line 106 of file G4AllocatorPool.hh.

◆ nchunks

int G4AllocatorPool::nchunks
private

Definition at line 107 of file G4AllocatorPool.hh.


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