Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Allocator< Type > Class Template Reference

#include <G4Allocator.hh>

Classes

struct  rebind
 

Public Types

typedef Type value_type
 
typedef size_t size_type
 
typedef ptrdiff_t difference_type
 
typedef Type * pointer
 
typedef const Type * const_pointer
 
typedef Type & reference
 
typedef const Type & const_reference
 

Public Member Functions

 G4Allocator () throw ()
 
 ~G4Allocator () throw ()
 
Type * MallocSingle ()
 
void FreeSingle (Type *anElement)
 
void ResetStorage ()
 
size_t GetAllocatedSize () const
 
int GetNoPages () const
 
size_t GetPageSize () const
 
void IncreasePageSize (unsigned int sz)
 
template<class U >
 G4Allocator (const G4Allocator< U > &right) throw ()
 
pointer address (reference r) const
 
const_pointer address (const_reference r) const
 
pointer allocate (size_type n, void *=0)
 
void deallocate (pointer p, size_type n)
 
void construct (pointer p, const Type &val)
 
void destroy (pointer p)
 
size_type max_size () const throw ()
 

Public Attributes

G4AllocatorPool mem
 

Detailed Description

template<class Type>
class G4Allocator< Type >

Definition at line 53 of file G4Allocator.hh.

Member Typedef Documentation

◆ const_pointer

template<class Type >
typedef const Type* G4Allocator< Type >::const_pointer

Definition at line 93 of file G4Allocator.hh.

◆ const_reference

template<class Type >
typedef const Type& G4Allocator< Type >::const_reference

Definition at line 95 of file G4Allocator.hh.

◆ difference_type

template<class Type >
typedef ptrdiff_t G4Allocator< Type >::difference_type

Definition at line 91 of file G4Allocator.hh.

◆ pointer

template<class Type >
typedef Type* G4Allocator< Type >::pointer

Definition at line 92 of file G4Allocator.hh.

◆ reference

template<class Type >
typedef Type& G4Allocator< Type >::reference

Definition at line 94 of file G4Allocator.hh.

◆ size_type

template<class Type >
typedef size_t G4Allocator< Type >::size_type

Definition at line 90 of file G4Allocator.hh.

◆ value_type

template<class Type >
typedef Type G4Allocator< Type >::value_type

Definition at line 89 of file G4Allocator.hh.

Constructor & Destructor Documentation

◆ G4Allocator() [1/2]

template<class Type >
G4Allocator< Type >::G4Allocator
throw (
)

Definition at line 160 of file G4Allocator.hh.

161 : mem(sizeof(Type))
162{
163}
G4AllocatorPool mem
Definition: G4Allocator.hh:143

◆ ~G4Allocator()

template<class Type >
G4Allocator< Type >::~G4Allocator
throw (
)

Definition at line 170 of file G4Allocator.hh.

171{
172}

◆ G4Allocator() [2/2]

template<class Type >
template<class U >
G4Allocator< Type >::G4Allocator ( const G4Allocator< U > &  right)
throw (
)
inline

Definition at line 97 of file G4Allocator.hh.

98 : mem(right.mem) {}

Member Function Documentation

◆ address() [1/2]

template<class Type >
const_pointer G4Allocator< Type >::address ( const_reference  r) const
inline

Definition at line 102 of file G4Allocator.hh.

102{ return &r; }

◆ address() [2/2]

template<class Type >
pointer G4Allocator< Type >::address ( reference  r) const
inline

Definition at line 101 of file G4Allocator.hh.

101{ return &r; }

◆ allocate()

template<class Type >
pointer G4Allocator< Type >::allocate ( size_type  n,
void *  = 0 
)
inline

Definition at line 105 of file G4Allocator.hh.

106 {
107 // Allocates space for n elements of type Type, but does not initialise
108 //
109 Type* mem_alloc = 0;
110 if (n == 1)
111 mem_alloc = MallocSingle();
112 else
113 mem_alloc = static_cast<Type*>(::operator new(n*sizeof(Type)));
114 return mem_alloc;
115 }
Type * MallocSingle()
Definition: G4Allocator.hh:179

◆ construct()

template<class Type >
void G4Allocator< Type >::construct ( pointer  p,
const Type &  val 
)
inline

Definition at line 127 of file G4Allocator.hh.

127{ new((void*)p) Type(val); }

◆ deallocate()

template<class Type >
void G4Allocator< Type >::deallocate ( pointer  p,
size_type  n 
)
inline

Definition at line 116 of file G4Allocator.hh.

117 {
118 // Deallocates n elements of type Type, but doesn't destroy
119 //
120 if (n == 1)
121 FreeSingle(p);
122 else
123 ::operator delete((void*)p);
124 return;
125 }
void FreeSingle(Type *anElement)
Definition: G4Allocator.hh:189

◆ destroy()

template<class Type >
void G4Allocator< Type >::destroy ( pointer  p)
inline

Definition at line 129 of file G4Allocator.hh.

129{ p->~Type(); }

◆ FreeSingle()

template<class Type >
void G4Allocator< Type >::FreeSingle ( Type *  anElement)
inline

Definition at line 189 of file G4Allocator.hh.

190{
191 mem.Free(anElement);
192 return;
193}
void Free(void *b)

Referenced by G4Allocator< Type >::deallocate().

◆ GetAllocatedSize()

template<class Type >
size_t G4Allocator< Type >::GetAllocatedSize
inline

Definition at line 213 of file G4Allocator.hh.

214{
215 return mem.Size();
216}
unsigned int Size() const

◆ GetNoPages()

template<class Type >
int G4Allocator< Type >::GetNoPages
inline

Definition at line 223 of file G4Allocator.hh.

224{
225 return mem.GetNoPages();
226}
int GetNoPages() const

◆ GetPageSize()

template<class Type >
size_t G4Allocator< Type >::GetPageSize
inline

Definition at line 233 of file G4Allocator.hh.

234{
235 return mem.GetPageSize();
236}
unsigned int GetPageSize() const

◆ IncreasePageSize()

template<class Type >
void G4Allocator< Type >::IncreasePageSize ( unsigned int  sz)
inline

Definition at line 243 of file G4Allocator.hh.

244{
245 ResetStorage();
246 mem.GrowPageSize(sz);
247}
void GrowPageSize(unsigned int factor)
void ResetStorage()
Definition: G4Allocator.hh:200

◆ MallocSingle()

template<class Type >
Type * G4Allocator< Type >::MallocSingle
inline

Definition at line 179 of file G4Allocator.hh.

180{
181 return static_cast<Type*>(mem.Alloc());
182}

Referenced by G4Allocator< Type >::allocate().

◆ max_size()

template<class Type >
size_type G4Allocator< Type >::max_size ( ) const
throw (
)
inline

Definition at line 132 of file G4Allocator.hh.

133 {
134 // Returns the maximum number of elements that can be allocated
135 //
136 return 2147483647/sizeof(Type);
137 }

◆ ResetStorage()

template<class Type >
void G4Allocator< Type >::ResetStorage
inline

Definition at line 200 of file G4Allocator.hh.

201{
202 // Clear all allocated storage and return it to the free store
203 //
204 mem.Reset();
205 return;
206}

Member Data Documentation

◆ mem

template<class Type >
G4AllocatorPool G4Allocator< Type >::mem

Definition at line 143 of file G4Allocator.hh.


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