Geant4 11.2.2
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 () override throw ()
 
TypeMallocSingle ()
 
void FreeSingle (Type *anElement)
 
void ResetStorage () override
 
std::size_t GetAllocatedSize () const override
 
int GetNoPages () const override
 
std::size_t GetPageSize () const override
 
void IncreasePageSize (unsigned int sz) override
 
const char * GetPoolType () const override
 
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 *=nullptr)
 
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 ()=default
 

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
const char * name(G4int ptype)

◆ ~G4Allocator()

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

◆ 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 * = nullptr )
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()

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

◆ 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

Definition at line 205 of file G4Allocator.hh.

206{
207 mem.Free(anElement);
208 return;
209}
void Free(void *b)

Referenced by G4Allocator< Type >::deallocate(), and G4KDNodeCopy< PointCopyT >::operator delete().

◆ GetAllocatedSize()

template<class Type >
std::size_t G4Allocator< Type >::GetAllocatedSize ( ) const
inlineoverridevirtual

Implements G4AllocatorBase.

Definition at line 229 of file G4Allocator.hh.

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

◆ GetNoPages()

template<class Type >
int G4Allocator< Type >::GetNoPages ( ) const
inlineoverridevirtual

Implements G4AllocatorBase.

Definition at line 239 of file G4Allocator.hh.

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

◆ GetPageSize()

template<class Type >
size_t G4Allocator< Type >::GetPageSize ( ) const
inlineoverridevirtual

Implements G4AllocatorBase.

Definition at line 249 of file G4Allocator.hh.

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

◆ GetPoolType()

template<class Type >
const char * G4Allocator< Type >::GetPoolType ( ) const
inlineoverridevirtual

Implements G4AllocatorBase.

Definition at line 270 of file G4Allocator.hh.

271{
272 return tname;
273}

◆ IncreasePageSize()

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

Implements G4AllocatorBase.

Definition at line 259 of file G4Allocator.hh.

260{
261 ResetStorage();
262 mem.GrowPageSize(sz);
263}
void GrowPageSize(unsigned int factor)
void ResetStorage() override

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

Implements G4AllocatorBase.

Definition at line 216 of file G4Allocator.hh.

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

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: