Geant4 11.1.1
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)=default
 
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 62 of file G4AllocatorPool.cc.

62{ Reset(); }

◆ G4AllocatorPool() [2/2]

G4AllocatorPool::G4AllocatorPool ( const G4AllocatorPool right)
default

Member Function Documentation

◆ Alloc()

void * G4AllocatorPool::Alloc ( )
inline

Definition at line 114 of file G4AllocatorPool.hh.

115{
116 if(head == nullptr)
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 auto* 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) != 0u ? sz * csize : csize;
161}

◆ operator=()

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

Definition at line 46 of file G4AllocatorPool.cc.

47{
48 if(&right == this)
49 {
50 return *this;
51 }
52 chunks = right.chunks;
53 head = right.head;
54 nchunks = right.nchunks;
55 return *this;
56}

◆ Reset()

void G4AllocatorPool::Reset ( )

Definition at line 68 of file G4AllocatorPool.cc.

69{
70 // Free all chunks
71 //
72 G4PoolChunk* n = chunks;
73 G4PoolChunk* p = nullptr;
74 while(n != nullptr)
75 {
76 p = n;
77 n = n->next;
78 delete p;
79 }
80 head = nullptr;
81 chunks = nullptr;
82 nchunks = 0;
83}

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: