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

#include <G4Allocator.hh>

+ Inheritance diagram for G4Allocator< Type >:

Classes

struct  rebind
 

Public Types

using value_type = Type
 
using size_type = std::size_t
 
using difference_type = ptrdiff_t
 
using pointer = Type *
 
using const_pointer = const Type *
 
using reference = Type &
 
using const_reference = const Type &
 

Public Member Functions

 G4Allocator () throw ()
 
 ~G4Allocator () throw ()
 
TypeMallocSingle ()
 
void FreeSingle (Type *anElement)
 
void ResetStorage ()
 
std::size_t GetAllocatedSize () const
 
int GetNoPages () const
 
std::size_t GetPageSize () const
 
void IncreasePageSize (unsigned int sz)
 
const char * GetPoolType () const
 
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 Member Functions inherited from G4AllocatorBase
 G4AllocatorBase ()
 
virtual ~G4AllocatorBase ()
 
virtual void ResetStorage ()=0
 
virtual std::size_t GetAllocatedSize () const =0
 
virtual int GetNoPages () const =0
 
virtual std::size_t GetPageSize () const =0
 
virtual void IncreasePageSize (unsigned int sz)=0
 
virtual const char * GetPoolType () const =0
 

Public Attributes

G4AllocatorPool mem
 

Detailed Description

template<class Type>
class G4Allocator< Type >

Definition at line 61 of file G4Allocator.hh.

Member Typedef Documentation

◆ const_pointer

template<class Type >
using G4Allocator< Type >::const_pointer = const Type*

Definition at line 101 of file G4Allocator.hh.

◆ const_reference

template<class Type >
using G4Allocator< Type >::const_reference = const Type&

Definition at line 103 of file G4Allocator.hh.

◆ difference_type

template<class Type >
using G4Allocator< Type >::difference_type = ptrdiff_t

Definition at line 99 of file G4Allocator.hh.

◆ pointer

template<class Type >
using G4Allocator< Type >::pointer = Type*

Definition at line 100 of file G4Allocator.hh.

◆ reference

template<class Type >
using G4Allocator< Type >::reference = Type&

Definition at line 102 of file G4Allocator.hh.

◆ size_type

template<class Type >
using G4Allocator< Type >::size_type = std::size_t

Definition at line 98 of file G4Allocator.hh.

◆ value_type

template<class Type >
using G4Allocator< Type >::value_type = Type

Definition at line 97 of file G4Allocator.hh.

Constructor & Destructor Documentation

◆ G4Allocator() [1/2]

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

Definition at line 177 of file G4Allocator.hh.

178 : mem(sizeof(Type))
179{
180 tname = typeid(Type).name();
181}
G4ProfileType Type
G4AllocatorPool mem
Definition: G4Allocator.hh:156
const char * name(G4int ptype)

◆ ~G4Allocator()

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

Definition at line 188 of file G4Allocator.hh.

189{}

◆ G4Allocator() [2/2]

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

Definition at line 106 of file G4Allocator.hh.

107 : mem(right.mem)
108 {}

Member Function Documentation

◆ address() [1/2]

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

Definition at line 112 of file G4Allocator.hh.

112{ return &r; }

◆ address() [2/2]

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

Definition at line 111 of file G4Allocator.hh.

111{ return &r; }

◆ allocate()

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

Definition at line 115 of file G4Allocator.hh.

116 {
117 // Allocates space for n elements of type Type, but does not initialise
118 //
119 Type* mem_alloc = 0;
120 if(n == 1)
121 mem_alloc = MallocSingle();
122 else
123 mem_alloc = static_cast<Type*>(::operator new(n * sizeof(Type)));
124 return mem_alloc;
125 }
Type * MallocSingle()
Definition: G4Allocator.hh:196

◆ construct()

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

Definition at line 137 of file G4Allocator.hh.

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

◆ deallocate()

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

Definition at line 126 of file G4Allocator.hh.

127 {
128 // Deallocates n elements of type Type, but doesn't destroy
129 //
130 if(n == 1)
131 FreeSingle(p);
132 else
133 ::operator delete((void*) p);
134 return;
135 }
void FreeSingle(Type *anElement)
Definition: G4Allocator.hh:206

◆ destroy()

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

Definition at line 139 of file G4Allocator.hh.

139{ p->~Type(); }

◆ FreeSingle()

◆ GetAllocatedSize()

template<class Type >
std::size_t G4Allocator< Type >::GetAllocatedSize
inlinevirtual

Implements G4AllocatorBase.

Definition at line 230 of file G4Allocator.hh.

231{
232 return mem.Size();
233}
unsigned int Size() const

◆ GetNoPages()

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

Implements G4AllocatorBase.

Definition at line 240 of file G4Allocator.hh.

241{
242 return mem.GetNoPages();
243}
int GetNoPages() const

◆ GetPageSize()

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

Implements G4AllocatorBase.

Definition at line 250 of file G4Allocator.hh.

251{
252 return mem.GetPageSize();
253}
unsigned int GetPageSize() const

◆ GetPoolType()

template<class Type >
const char * G4Allocator< Type >::GetPoolType
inlinevirtual

Implements G4AllocatorBase.

Definition at line 271 of file G4Allocator.hh.

272{
273 return tname;
274}

◆ IncreasePageSize()

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

Implements G4AllocatorBase.

Definition at line 260 of file G4Allocator.hh.

261{
262 ResetStorage();
263 mem.GrowPageSize(sz);
264}
void GrowPageSize(unsigned int factor)
void ResetStorage()
Definition: G4Allocator.hh:217

◆ MallocSingle()

◆ max_size()

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

Definition at line 142 of file G4Allocator.hh.

143 {
144 // Returns the maximum number of elements that can be allocated
145 //
146 return 2147483647 / sizeof(Type);
147 }

◆ ResetStorage()

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

Implements G4AllocatorBase.

Definition at line 217 of file G4Allocator.hh.

218{
219 // Clear all allocated storage and return it to the free store
220 //
221 mem.Reset();
222 return;
223}

Member Data Documentation

◆ mem

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

Definition at line 156 of file G4Allocator.hh.


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