Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AllocatorPool Class Reference

#include <G4AllocatorPool.hh>

Public Member Functions

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

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{}

◆ ~G4AllocatorPool()

G4AllocatorPool::~G4AllocatorPool ( )

Definition at line 74 of file G4AllocatorPool.cc.

74{ 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{}

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}

◆ 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}

◆ GetNoPages()

int G4AllocatorPool::GetNoPages ( ) const
inline

Definition at line 146 of file G4AllocatorPool.hh.

146{ return nchunks; }

◆ GetPageSize()

unsigned int G4AllocatorPool::GetPageSize ( ) const
inline

Definition at line 152 of file G4AllocatorPool.hh.

152{ return csize; }

◆ GrowPageSize()

void G4AllocatorPool::GrowPageSize ( unsigned int  factor)
inline

Definition at line 158 of file G4AllocatorPool.hh.

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

◆ 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}

◆ 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}

Referenced by ~G4AllocatorPool().

◆ Size()

unsigned int G4AllocatorPool::Size ( ) const
inline

Definition at line 140 of file G4AllocatorPool.hh.

140{ return nchunks * csize; }

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