Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4EnhancedVecAllocator< _Tp > Class Template Reference

#include <G4EnhancedVecAllocator.hh>

+ Inheritance diagram for G4EnhancedVecAllocator< _Tp >:

Classes

struct  rebind
 

Public Member Functions

 G4EnhancedVecAllocator ()
 
 G4EnhancedVecAllocator (const G4EnhancedVecAllocator< _Tp > &)
 
template<typename _Tp1 >
 G4EnhancedVecAllocator (const G4EnhancedVecAllocator< _Tp1 > &)
 
 ~G4EnhancedVecAllocator ()
 
void deallocate (_Tp *_Ptr, std::size_t _Count)
 
_Tp * allocate (std::size_t _Count)
 

Detailed Description

template<typename _Tp>
class G4EnhancedVecAllocator< _Tp >

Definition at line 70 of file G4EnhancedVecAllocator.hh.

Constructor & Destructor Documentation

◆ G4EnhancedVecAllocator() [1/3]

template<typename _Tp >
G4EnhancedVecAllocator< _Tp >::G4EnhancedVecAllocator ( )
inline

Definition at line 77 of file G4EnhancedVecAllocator.hh.

77{;}

◆ G4EnhancedVecAllocator() [2/3]

template<typename _Tp >
G4EnhancedVecAllocator< _Tp >::G4EnhancedVecAllocator ( const G4EnhancedVecAllocator< _Tp > & )
inline

Definition at line 79 of file G4EnhancedVecAllocator.hh.

80 : std::allocator<_Tp>() {;}

◆ G4EnhancedVecAllocator() [3/3]

template<typename _Tp >
template<typename _Tp1 >
G4EnhancedVecAllocator< _Tp >::G4EnhancedVecAllocator ( const G4EnhancedVecAllocator< _Tp1 > & )
inline

Definition at line 83 of file G4EnhancedVecAllocator.hh.

84 : std::allocator<_Tp>() {;}

◆ ~G4EnhancedVecAllocator()

template<typename _Tp >
G4EnhancedVecAllocator< _Tp >::~G4EnhancedVecAllocator ( )
inline

Definition at line 86 of file G4EnhancedVecAllocator.hh.

86{;}

Member Function Documentation

◆ allocate()

template<typename _Tp >
_Tp * G4EnhancedVecAllocator< _Tp >::allocate ( std::size_t _Count)

Definition at line 145 of file G4EnhancedVecAllocator.hh.

147{
148 std::size_t totalsize = _Count * sizeof(_Tp);
149
150 G4int found = -1;
152 {
153 for (auto j = 0 ; j < G4AllocStats::numCat ; ++j)
154 {
155 if (G4AllocStats::allocStat[j].size == totalsize)
156 {
157 found = j;
158 break;
159 }
160 }
161 }
162
163 if (found == -1) // Find the new size
164 {
167 {
169 // heuristic parameter for different sizes
170
174 // This value must be different than zero; otherwise means
175 // failure in allocating extra space !
176 // assert(G4AllocStats::allocStat != 0);
177 }
178
182
183 found = G4AllocStats::numCat - 1;
185
186 chunk.totalspace = 512;
187 // heuristic for the number of STL vector instances
188
189 chunk.preAllocated = (G4ChunkType *) realloc(chunk.preAllocated,
190 sizeof(G4ChunkType) * chunk.totalspace);
191 // This value must be different than zero; otherwise means
192 // failure in allocating extra space for pointers !
193 // assert(chunk.preAllocated != 0);
194
195 char *newSpace1 = (char *) malloc(totalsize * 512);
196 // This pointer must be different than zero; otherwise means
197 // failure in allocating extra space for instances !
198 // assert(newSpace1 != 0);
199
200 for (auto k = 0; k < 512 ; ++k)
201 {
202 (chunk.preAllocated[k]).isAllocated = 0;
203 (chunk.preAllocated[k]).address = newSpace1+totalsize*k;
204 }
205
206 (chunk.preAllocated[0]).isAllocated = 1;
207 return (_Tp*)((chunk.preAllocated[0]).address);
208 }
209
211
212 // assert(chunk.size == totalsize);
213
214 for (auto k = 0; k < chunk.totalspace; ++k)
215 {
216 if ((chunk.preAllocated[k]).isAllocated == 0)
217 {
218 (chunk.preAllocated[k]).isAllocated = 1;
219 return (_Tp*)((chunk.preAllocated[k]).address);
220 }
221 }
222
223 G4int originalchunknumber = chunk.totalspace;
224
225 chunk.totalspace += 512; // heuristic for the number of STL vector instances
226
227 chunk.preAllocated = (G4ChunkType *) realloc(chunk.preAllocated,
228 sizeof(G4ChunkType) * chunk.totalspace);
229 // This value must be different than zero; otherwise means
230 // failure in allocating extra space for pointers !
231 // assert(chunk.preAllocated != 0);
232
233 char *newSpace = (char *) malloc(totalsize * 512);
234 // This pointer must be different than zero; otherwise means
235 // failure in allocating extra space for instances !
236 // assert(newSpace != 0);
237
238 for (auto k = 0; k < 512 ; ++k)
239 {
240 (chunk.preAllocated[originalchunknumber+k]).isAllocated = 0;
241 (chunk.preAllocated[originalchunknumber+k]).address = newSpace+totalsize*k;
242 }
243
244 (chunk.preAllocated[originalchunknumber]).isAllocated = 1;
245
246 return (_Tp*)((chunk.preAllocated[originalchunknumber]).address);
247}
int G4int
Definition G4Types.hh:85
static G4ThreadLocal G4int totSpace
static G4ThreadLocal G4ChunkIndexType * allocStat
static G4ThreadLocal G4int numCat

◆ deallocate()

template<typename _Tp >
void G4EnhancedVecAllocator< _Tp >::deallocate ( _Tp * _Ptr,
std::size_t _Count )

Definition at line 107 of file G4EnhancedVecAllocator.hh.

108{
109 G4int found = -1;
111 {
112 for (auto j = 0 ; j < G4AllocStats::numCat ; ++j)
113 {
114 if (G4AllocStats::allocStat[j].size == (_Count * sizeof(_Tp)))
115 {
116 found = j;
117 break;
118 }
119 }
120 }
121 // assert(found != -1);
122
124
125 for (auto k = 0; k < chunk.totalspace; ++k)
126 {
127 if ( (chunk.preAllocated[k]).address == ((char *) _Ptr))
128 {
129 // assert((chunk.preAllocated[k]).isAllocated==1);
130 (chunk.preAllocated[k]).isAllocated = 0;
131 return;
132 }
133 }
134}

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