Geant4 9.6.0
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, size_t _Count)
 
_Tp * allocate (size_t _Count)
 

Detailed Description

template<typename _Tp>
class G4EnhancedVecAllocator< _Tp >

Definition at line 80 of file G4EnhancedVecAllocator.hh.

Constructor & Destructor Documentation

◆ G4EnhancedVecAllocator() [1/3]

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

Definition at line 87 of file G4EnhancedVecAllocator.hh.

87{;}

◆ G4EnhancedVecAllocator() [2/3]

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

Definition at line 89 of file G4EnhancedVecAllocator.hh.

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

◆ G4EnhancedVecAllocator() [3/3]

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

Definition at line 93 of file G4EnhancedVecAllocator.hh.

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

◆ ~G4EnhancedVecAllocator()

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

Definition at line 96 of file G4EnhancedVecAllocator.hh.

96{;}

Member Function Documentation

◆ allocate()

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

Definition at line 152 of file G4EnhancedVecAllocator.hh.

154{
155 size_t totalsize = _Count * sizeof(_Tp);
156
157 G4int found = -1;
158 for (register int j = 0 ; j < G4AllocStats::numCat ; j++)
159 {
160 if ( (G4AllocStats::allocStat != 0)
161 && (G4AllocStats::allocStat[j].size == totalsize) )
162 {
163 found = j;
164 break;
165 }
166 }
167
168 if (found == -1) // Find the new size
169 {
172 {
174 // heuristic parameter for different sizes
175
179 // This value must be different than zero; otherwise means
180 // failure in allocating extra space !
181 // assert(G4AllocStats::allocStat != 0);
182 }
183
187
188 found = G4AllocStats::numCat - 1;
189
191 // heuristic for the number of STL vector instances
192
194 (G4ChunkType *) realloc(G4AllocStats::allocStat[found].preAllocated,
196 // This value must be different than zero; otherwise means
197 // failure in allocating extra space for pointers !
198 // assert(G4AllocStats::allocStat[found].preAllocated != 0);
199
200 char *newSpace1 = (char *) malloc(totalsize * 512);
201 // This pointer must be different than zero; otherwise means
202 // failure in allocating extra space for instances !
203 // assert(newSpace1 != 0);
204
205 for (register int k = 0; k < 512 ; k++)
206 {
207 ((G4AllocStats::allocStat[found]).preAllocated[k]).isAllocated = 0;
208 ((G4AllocStats::allocStat[found]).preAllocated[k]).address =
209 newSpace1+totalsize*k;
210 }
211
212 ((G4AllocStats::allocStat[found]).preAllocated[0]).isAllocated = 1;
213 return (_Tp*)(((G4AllocStats::allocStat[found]).preAllocated[0]).address);
214 }
215
216 // assert(G4AllocStats::allocStat[found].size == totalsize);
217
218 for (register int k = 0; k < G4AllocStats::allocStat[found].totalspace; k++)
219 {
220 if (((G4AllocStats::allocStat[found]).preAllocated[k]).isAllocated == 0)
221 {
222 ((G4AllocStats::allocStat[found]).preAllocated[k]).isAllocated = 1;
223 return (_Tp*)(((G4AllocStats::allocStat[found]).preAllocated[k]).address);
224 }
225 }
226
227 G4int originalchunknumber = G4AllocStats::allocStat[found].totalspace;
228
229 G4AllocStats::allocStat[found].totalspace = // heuristic for the number
230 G4AllocStats::allocStat[found].totalspace+512; // of STL vector instances
231
233 (G4ChunkType *) realloc(G4AllocStats::allocStat[found].preAllocated,
235 // This value must be different than zero; otherwise means
236 // failure in allocating extra space for pointers !
237 // assert(G4AllocStats::allocStat[found].preAllocated != 0);
238
239 char *newSpace = (char *) malloc(totalsize * 512);
240 // This pointer must be different than zero; otherwise means
241 // failure in allocating extra space for instances !
242 // assert(newSpace != 0);
243
244 for (register int k = 0; k < 512 ; k++)
245 {
246 ((G4AllocStats::allocStat[found]).
247 preAllocated[originalchunknumber + k]).isAllocated= 0;
248 ((G4AllocStats::allocStat[found]).
249 preAllocated[originalchunknumber + k]).address= newSpace+totalsize*k;
250 }
251
252 ((G4AllocStats::allocStat[found]).preAllocated[originalchunknumber])
253 .isAllocated = 1;
254
255 return (_Tp*)(((G4AllocStats::allocStat[found]).
256 preAllocated[originalchunknumber]).address);
257}
int G4int
Definition: G4Types.hh:66
static G4ChunkIndexType * allocStat

◆ deallocate()

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

Definition at line 117 of file G4EnhancedVecAllocator.hh.

118{
119 G4int found = -1;
120 for (register int j = 0 ; j < G4AllocStats::numCat ; j++)
121 {
122 if ( (G4AllocStats::allocStat != 0)
123 && (G4AllocStats::allocStat[j].size == (_Count * sizeof(_Tp))))
124 {
125 found = j;
126 break;
127 }
128 }
129 // assert(found != -1);
130
131 for (register int k = 0; k < G4AllocStats::allocStat[found].totalspace; k++)
132 {
133 if ( ((G4AllocStats::allocStat[found]).preAllocated[k]).address
134 == ((char *) _Ptr))
135 {
136 // assert(((G4AllocStats::allocStat[found]).preAllocated[k]).isAllocated==1);
137 ((G4AllocStats::allocStat[found]).preAllocated[k]).isAllocated = 0;
138 return;
139 }
140 }
141}

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