Geant4-11
Data Structures | Public Types | Public Member Functions | Data Fields | Private Attributes
G4Allocator< Type > Class Template Reference

#include <G4Allocator.hh>

Inheritance diagram for G4Allocator< Type >:
G4AllocatorBase

Data Structures

struct  rebind
 

Public Types

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

Public Member Functions

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

Data Fields

G4AllocatorPool mem
 

Private Attributes

const char * tname
 

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
const char * tname
Definition: G4Allocator.hh:160
G4AllocatorPool mem
Definition: G4Allocator.hh:156
const char * name(G4int ptype)

References G4InuclParticleNames::name().

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

References G4Allocator< Type >::MallocSingle(), and CLHEP::detail::n.

◆ 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

References G4Allocator< Type >::FreeSingle(), and CLHEP::detail::n.

◆ destroy()

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

Definition at line 139 of file G4Allocator.hh.

139{ p->~Type(); }

◆ FreeSingle()

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

◆ 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()

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

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

Field Documentation

◆ mem

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

Definition at line 156 of file G4Allocator.hh.

◆ tname

template<class Type >
const char* G4Allocator< Type >::tname
private

Definition at line 160 of file G4Allocator.hh.


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