Geant4-11
Data Structures | Public Member Functions | Private Member Functions | Private Attributes
G4AllocatorPool Class Reference

#include <G4AllocatorPool.hh>

Data Structures

class  G4PoolChunk
 
struct  G4PoolLink
 

Public Member Functions

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

Private Member Functions

void Grow ()
 

Private Attributes

G4PoolChunkchunks = nullptr
 
unsigned int csize
 
const unsigned int esize
 
G4PoolLinkhead = nullptr
 
int nchunks = 0
 

Detailed Description

Definition at line 44 of file G4AllocatorPool.hh.

Constructor & Destructor Documentation

◆ G4AllocatorPool() [1/2]

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

Definition at line 37 of file G4AllocatorPool.cc.

38 : esize(sz < sizeof(G4PoolLink) ? sizeof(G4PoolLink) : sz)
39 , csize(sz < 1024 / 2 - 16 ? 1024 - 16 : sz * 10 - 16)
40{}
const unsigned int esize
unsigned int csize

◆ ~G4AllocatorPool()

G4AllocatorPool::~G4AllocatorPool ( )

Definition at line 74 of file G4AllocatorPool.cc.

74{ Reset(); }

References Reset().

◆ G4AllocatorPool() [2/2]

G4AllocatorPool::G4AllocatorPool ( const G4AllocatorPool right)

Definition at line 46 of file G4AllocatorPool.cc.

47 : esize(right.esize)
48 , csize(right.csize)
49 , chunks(right.chunks)
50 , head(right.head)
51 , nchunks(right.nchunks)
52{}
G4PoolLink * head
G4PoolChunk * chunks

Member Function Documentation

◆ Alloc()

void * G4AllocatorPool::Alloc ( )
inline

Definition at line 114 of file G4AllocatorPool.hh.

115{
116 if(head == 0)
117 {
118 Grow();
119 }
120 G4PoolLink* p = head; // return first element
121 head = p->next;
122 return p;
123}

References Grow(), head, and G4AllocatorPool::G4PoolLink::next.

◆ Free()

void G4AllocatorPool::Free ( void *  b)
inline

Definition at line 129 of file G4AllocatorPool.hh.

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

References head, and G4AllocatorPool::G4PoolLink::next.

◆ GetNoPages()

int G4AllocatorPool::GetNoPages ( ) const
inline

Definition at line 146 of file G4AllocatorPool.hh.

146{ return nchunks; }

References nchunks.

◆ GetPageSize()

unsigned int G4AllocatorPool::GetPageSize ( ) const
inline

Definition at line 152 of file G4AllocatorPool.hh.

152{ return csize; }

References csize.

◆ Grow()

void G4AllocatorPool::Grow ( )
private

Definition at line 101 of file G4AllocatorPool.cc.

102{
103 // Allocate new chunk, organize it as a linked list of
104 // elements of size 'esize'
105 //
106 G4PoolChunk* n = new G4PoolChunk(csize);
107 n->next = chunks;
108 chunks = n;
109 ++nchunks;
110
111 const int nelem = csize / esize;
112 char* start = n->mem;
113 char* last = &start[(nelem - 1) * esize];
114 for(char* p = start; p < last; p += esize)
115 {
116 reinterpret_cast<G4PoolLink*>(p)->next =
117 reinterpret_cast<G4PoolLink*>(p + esize);
118 }
119 reinterpret_cast<G4PoolLink*>(last)->next = nullptr;
120 head = reinterpret_cast<G4PoolLink*>(start);
121}

References chunks, csize, esize, head, CLHEP::detail::n, and nchunks.

Referenced by Alloc().

◆ GrowPageSize()

void G4AllocatorPool::GrowPageSize ( unsigned int  factor)
inline

Definition at line 158 of file G4AllocatorPool.hh.

159{
160 csize = (sz) ? sz * csize : csize;
161}

References csize.

◆ operator=()

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

Definition at line 58 of file G4AllocatorPool.cc.

59{
60 if(&right == this)
61 {
62 return *this;
63 }
64 chunks = right.chunks;
65 head = right.head;
66 nchunks = right.nchunks;
67 return *this;
68}

References chunks, head, and nchunks.

◆ Reset()

void G4AllocatorPool::Reset ( )

Definition at line 80 of file G4AllocatorPool.cc.

81{
82 // Free all chunks
83 //
84 G4PoolChunk* n = chunks;
85 G4PoolChunk* p = nullptr;
86 while(n)
87 {
88 p = n;
89 n = n->next;
90 delete p;
91 }
92 head = nullptr;
93 chunks = nullptr;
94 nchunks = 0;
95}

References chunks, head, CLHEP::detail::n, and nchunks.

Referenced by ~G4AllocatorPool().

◆ Size()

unsigned int G4AllocatorPool::Size ( ) const
inline

Definition at line 140 of file G4AllocatorPool.hh.

140{ return nchunks * csize; }

References csize, and nchunks.

Field Documentation

◆ chunks

G4PoolChunk* G4AllocatorPool::chunks = nullptr
private

Definition at line 101 of file G4AllocatorPool.hh.

Referenced by Grow(), operator=(), and Reset().

◆ csize

unsigned int G4AllocatorPool::csize
private

Definition at line 100 of file G4AllocatorPool.hh.

Referenced by GetPageSize(), Grow(), GrowPageSize(), and Size().

◆ esize

const unsigned int G4AllocatorPool::esize
private

Definition at line 99 of file G4AllocatorPool.hh.

Referenced by Grow().

◆ head

G4PoolLink* G4AllocatorPool::head = nullptr
private

Definition at line 102 of file G4AllocatorPool.hh.

Referenced by Alloc(), Free(), Grow(), operator=(), and Reset().

◆ nchunks

int G4AllocatorPool::nchunks = 0
private

Definition at line 103 of file G4AllocatorPool.hh.

Referenced by GetNoPages(), Grow(), operator=(), Reset(), and Size().


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