Geant4-11
Data Structures | Public Member Functions
G4EnhancedVecAllocator< _Tp > Class Template Reference

#include <G4EnhancedVecAllocator.hh>

Inheritance diagram for G4EnhancedVecAllocator< _Tp >:

Data Structures

struct  rebind
 

Public Member Functions

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

Detailed Description

template<typename _Tp>
class G4EnhancedVecAllocator< _Tp >

Definition at line 71 of file G4EnhancedVecAllocator.hh.

Constructor & Destructor Documentation

◆ G4EnhancedVecAllocator() [1/3]

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

Definition at line 78 of file G4EnhancedVecAllocator.hh.

78{;}

◆ G4EnhancedVecAllocator() [2/3]

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

Definition at line 80 of file G4EnhancedVecAllocator.hh.

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

◆ G4EnhancedVecAllocator() [3/3]

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

Definition at line 84 of file G4EnhancedVecAllocator.hh.

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

◆ ~G4EnhancedVecAllocator()

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

Definition at line 87 of file G4EnhancedVecAllocator.hh.

87{;}

Member Function Documentation

◆ allocate()

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

Definition at line 146 of file G4EnhancedVecAllocator.hh.

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

References G4AllocStats::allocStat, G4AllocStats::numCat, G4ChunkIndexType::preAllocated, G4ChunkIndexType::size, G4ChunkIndexType::totalspace, and G4AllocStats::totSpace.

◆ deallocate()

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

Definition at line 108 of file G4EnhancedVecAllocator.hh.

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

References G4AllocStats::allocStat, G4AllocStats::numCat, G4ChunkIndexType::preAllocated, and G4ChunkIndexType::totalspace.


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