Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions | Variables
hjmalloc.cc File Reference
#include <iostream>
#include <stdio.h>
#include <time.h>
#include "tls.hh"
#include "tpmalloc/mymalloc.h"

Go to the source code of this file.

Macros

#define HJMALLOCDEBUG   0
 
#define HJMALLOCPROFILE   0
 
#define TLMSSIZE   256
 

Functions

void turnontpmalloc ()
 
void turnofftpmalloc ()
 
int tpmallocflag ()
 
voidmalloc (size_t __size)
 
voidcalloc (size_t __nmemb, size_t __size)
 
voidrealloc (void *__ptr, size_t __size)
 
void free (void *__ptr)
 
void cfree (void *__ptr)
 
voidvalloc (size_t __size)
 

Variables

G4ThreadLocal int mallocswitch = 0
 
G4ThreadLocal mspace tlms = 0
 
G4ThreadLocal long int alloccount = 0
 
G4ThreadLocal long int freecount = 0
 
G4ThreadLocal double alloctime = 0.0
 
G4ThreadLocal double freetime = 0.0
 

Macro Definition Documentation

#define HJMALLOCDEBUG   0

Definition at line 17 of file hjmalloc.cc.

#define HJMALLOCPROFILE   0

Definition at line 18 of file hjmalloc.cc.

#define TLMSSIZE   256

Definition at line 21 of file hjmalloc.cc.

Referenced by calloc(), malloc(), realloc(), and valloc().

Function Documentation

void* calloc ( size_t  __nmemb,
size_t  __size 
)

Definition at line 67 of file hjmalloc.cc.

References alloccount, alloctime, create_mspace(), mallocswitch, mspace_calloc(), tlms, and TLMSSIZE.

Referenced by main(), and zcalloc().

68 {
69  #if HJMALLOCPROFILE
70  alloccount++;
71  #endif
72 
73  #if HJMALLOCDEBUG
74  std::cout << "in calloc of mymalloc" << std::endl;
75  #endif
76  if (mallocswitch == 0)
77  return mycalloc(__nmemb, __size);
78  else
79  {
80  #if HJMALLOCDEBUG
81  std::cout << "mspace in alloc of mymalloc" << std::endl;
82  #endif
83  if (tlms == 0) tlms = create_mspace(TLMSSIZE * 1024 * 1024, 0);
84 
85  #if HJMALLOCPROFILE
86  double timed;
87  struct timespec ts1, ts2;
88  clock_gettime(CLOCK_REALTIME, &ts1);
89  #endif
90 
91  void *tempmalloc = mspace_calloc(tlms, __nmemb, __size);
92 
93  #if HJMALLOCPROFILE
94  clock_gettime(CLOCK_REALTIME, &ts2);
95  timed = (ts2.tv_sec - ts1.tv_sec) * 1000000000 + (ts2.tv_nsec - ts1.tv_nsec);
96  alloctime = alloctime + timed;
97  #endif
98 
99  return tempmalloc;
100  }
101 }
G4ThreadLocal mspace tlms
Definition: hjmalloc.cc:9
#define TLMSSIZE
Definition: hjmalloc.cc:21
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
G4ThreadLocal double alloctime
Definition: hjmalloc.cc:14
mspace create_mspace(size_t capacity, int locked)
Definition: mymalloc.cc:4974
void * mspace_calloc(mspace msp, size_t n_elements, size_t elem_size)
Definition: mymalloc.cc:5276
G4ThreadLocal long int alloccount
Definition: hjmalloc.cc:11
void cfree ( void __ptr)

Definition at line 174 of file hjmalloc.cc.

References freecount, freetime, mallocswitch, mspace_free(), and tlms.

175 {
176  #if HJMALLOCPROFILE
177  freecount++;
178  #endif
179 
180  #if HJMALLOCDEBUG
181  std::cout << "in cfree of mymalloc" << std::endl;
182  #endif
183  if (mallocswitch == 0)
184  cfree(__ptr);
185  else
186  {
187  #if HJMALLOCDEBUG
188  std::cout << "mspace in cfree of mymalloc" << std::endl;
189  #endif
190 
191  #if HJMALLOCPROFILE
192  double timed;
193  struct timespec ts1, ts2;
194  clock_gettime(CLOCK_REALTIME, &ts1);
195  #endif
196 
197  mspace_free(tlms, __ptr);
198 
199  #if HJMALLOCPROFILE
200  clock_gettime(CLOCK_REALTIME, &ts2);
201  timed = (ts2.tv_sec - ts1.tv_sec) * 1000000000 + (ts2.tv_nsec - ts1.tv_nsec);
202  freetime = freetime + timed;
203  #endif
204 
205  }
206 }
G4ThreadLocal mspace tlms
Definition: hjmalloc.cc:9
G4ThreadLocal double freetime
Definition: hjmalloc.cc:15
G4ThreadLocal long int freecount
Definition: hjmalloc.cc:12
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
void cfree(void *__ptr)
Definition: hjmalloc.cc:174
void mspace_free(mspace msp, void *mem)
Definition: mymalloc.cc:5175
void free ( void __ptr)

Definition at line 140 of file hjmalloc.cc.

References freecount, freetime, mallocswitch, mspace_free(), and tlms.

Referenced by G4PDefSplitter< T >::FreeSlave(), G4VUPLSplitter< T >::FreeSlave(), G4GeomSplitter< T >::FreeSlave(), GetWords(), gString_release(), gz_error(), gz_init(), gz_look(), gz_open(), gzclose_r(), gzclose_w(), gzdopen(), main(), parsedir(), G4VInteractorManager::SetArguments(), smr_release(), tpi_spectralID_release(), tpia_misc_setMessageError_Element(), xData_free(), zcfree(), G4VInteractorManager::~G4VInteractorManager(), and MarshaledObj::~MarshaledObj().

141 {
142  #if HJMALLOCPROFILE
143  freecount++;
144  #endif
145 
146  #if HJMALLOCDEBUG
147  std::cout << "in free of mymalloc" << std::endl;
148  #endif
149  if (mallocswitch == 0)
150  myfree(__ptr);
151  else
152  {
153  #if HJMALLOCDEBUG
154  std::cout << "mspace in free of mymalloc" << std::endl;
155  #endif
156 
157  #if HJMALLOCPROFILE
158  double timed;
159  struct timespec ts1, ts2;
160  clock_gettime(CLOCK_REALTIME, &ts1);
161  #endif
162 
163  mspace_free(tlms, __ptr);
164 
165  #if HJMALLOCPROFILE
166  clock_gettime(CLOCK_REALTIME, &ts2);
167  timed = (ts2.tv_sec - ts1.tv_sec) * 1000000000 + (ts2.tv_nsec - ts1.tv_nsec);
168  freetime = freetime + timed;
169  #endif
170 
171  }
172 }
G4ThreadLocal mspace tlms
Definition: hjmalloc.cc:9
G4ThreadLocal double freetime
Definition: hjmalloc.cc:15
G4ThreadLocal long int freecount
Definition: hjmalloc.cc:12
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
void mspace_free(mspace msp, void *mem)
Definition: mymalloc.cc:5175
void* malloc ( size_t  __size)

Definition at line 30 of file hjmalloc.cc.

References alloccount, alloctime, create_mspace(), mallocswitch, mspace_malloc(), tlms, and TLMSSIZE.

Referenced by G4EnhancedVecAllocator< _Tp >::allocate(), AllocateInProtectedHeap(), GetWords(), gz_error(), gz_init(), gz_look(), gz_open(), gzdopen(), insertAddress(), main(), MarshaledObj::MarshaledObj(), parsedir(), G4VInteractorManager::SetArguments(), and zcalloc().

31 {
32  #if HJMALLOCPROFILE
33  alloccount++;
34  #endif
35 
36  #if HJMALLOCDEBUG
37  std::cout << "in malloc of mymalloc" << std::endl;
38  #endif
39 
40  if (mallocswitch == 0)
41  return mymalloc(__size);
42  else
43  {
44  #if HJMALLOCDEBUG
45  std::cout << "mspace in malloc of mymalloc" << std::endl;
46  #endif
47  if (tlms == 0) tlms = create_mspace(TLMSSIZE * 1024 * 1024, 0);
48 
49  #if HJMALLOCPROFILE
50  double timed;
51  struct timespec ts1, ts2;
52  clock_gettime(CLOCK_REALTIME, &ts1);
53  #endif
54 
55  void *tempmalloc = mspace_malloc(tlms, __size);
56 
57  #if HJMALLOCPROFILE
58  clock_gettime(CLOCK_REALTIME, &ts2);
59  timed = (ts2.tv_sec - ts1.tv_sec) * 1000000000 + (ts2.tv_nsec - ts1.tv_nsec);
60  alloctime = alloctime + timed;
61  #endif
62 
63  return tempmalloc;
64  }
65 }
G4ThreadLocal mspace tlms
Definition: hjmalloc.cc:9
void * mspace_malloc(mspace msp, size_t bytes)
Definition: mymalloc.cc:5061
#define TLMSSIZE
Definition: hjmalloc.cc:21
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
G4ThreadLocal double alloctime
Definition: hjmalloc.cc:14
mspace create_mspace(size_t capacity, int locked)
Definition: mymalloc.cc:4974
G4ThreadLocal long int alloccount
Definition: hjmalloc.cc:11
void* realloc ( void __ptr,
size_t  __size 
)

Definition at line 103 of file hjmalloc.cc.

References alloccount, alloctime, create_mspace(), freecount, mallocswitch, mspace_realloc(), tlms, and TLMSSIZE.

Referenced by G4EnhancedVecAllocator< _Tp >::allocate(), G4GeomSplitter< T >::CreateSubInstance(), GetWords(), insertAddress(), G4PDefSplitter< T >::NewSubInstances(), G4VUPLSplitter< T >::NewSubInstances(), MarshaledObj::resizeBuffer(), G4GeomSplitter< T >::SlaveCopySubInstanceArray(), G4VUPLSplitter< T >::SlaveCopySubInstanceArray(), G4GeomSplitter< T >::SlaveInitializeSubInstance(), smr_vallocateFormatMessage(), and xData_realloc().

104 {
105  #if HJMALLOCPROFILE
106  alloccount++;
107  freecount++;
108  #endif
109 
110  #if HJMALLOCDEBUG
111  std::cout << "in realloc of mymalloc" << std::endl;
112  #endif
113  if (mallocswitch == 0)
114  return myrealloc(__ptr, __size);
115  else
116  {
117  #if HJMALLOCDEBUG
118  std::cout << "mspace in realloc of mymalloc" << std::endl;
119  #endif
120  if (tlms == 0) tlms = create_mspace(TLMSSIZE * 1024 * 1024, 0);
121 
122  #if HJMALLOCPROFILE
123  double timed;
124  struct timespec ts1, ts2;
125  clock_gettime(CLOCK_REALTIME, &ts1);
126  #endif
127 
128  void *tempmalloc = mspace_realloc(tlms, __ptr, __size);
129 
130  #if HJMALLOCPROFILE
131  clock_gettime(CLOCK_REALTIME, &ts2);
132  timed = (ts2.tv_sec - ts1.tv_sec) * 1000000000 + (ts2.tv_nsec - ts1.tv_nsec);
133  alloctime = alloctime + timed;
134  #endif
135 
136  return tempmalloc;
137  }
138 }
G4ThreadLocal mspace tlms
Definition: hjmalloc.cc:9
#define TLMSSIZE
Definition: hjmalloc.cc:21
G4ThreadLocal long int freecount
Definition: hjmalloc.cc:12
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
G4ThreadLocal double alloctime
Definition: hjmalloc.cc:14
void * mspace_realloc(mspace msp, void *mem, size_t newsize)
Definition: mymalloc.cc:5296
mspace create_mspace(size_t capacity, int locked)
Definition: mymalloc.cc:4974
G4ThreadLocal long int alloccount
Definition: hjmalloc.cc:11
int tpmallocflag ( )

Definition at line 28 of file hjmalloc.cc.

References mallocswitch.

28 {return mallocswitch;}
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
void turnofftpmalloc ( )

Definition at line 27 of file hjmalloc.cc.

References mallocswitch.

27 {mallocswitch = 0;}
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
void turnontpmalloc ( )

Definition at line 26 of file hjmalloc.cc.

References mallocswitch.

26 {mallocswitch = 1;}
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
void* valloc ( size_t  __size)

Definition at line 208 of file hjmalloc.cc.

References alloccount, alloctime, create_mspace(), mallocswitch, mspace_malloc(), tlms, and TLMSSIZE.

209 {
210  #if HJMALLOCPROFILE
211  alloccount++;
212  #endif
213 
214  #if HJMALLOCDEBUG
215  std::cout << "in valloc of mymalloc" << std::endl;
216  #endif
217  if (mallocswitch == 0)
218  return myvalloc(__size);
219  else
220  {
221  #if HJMALLOCDEBUG
222  std::cout << "mspace in valloc of mymalloc" << std::endl;
223  #endif
224  if (tlms == 0) tlms = create_mspace(TLMSSIZE * 1024 * 1024, 0);
225 
226  #if HJMALLOCPROFILE
227  double timed;
228  struct timespec ts1, ts2;
229  clock_gettime(CLOCK_REALTIME, &ts1);
230  #endif
231 
232  void *tempmalloc = mspace_malloc(tlms, __size);
233 
234  #if HJMALLOCPROFILE
235  clock_gettime(CLOCK_REALTIME, &ts2);
236  timed = (ts2.tv_sec - ts1.tv_sec) * 1000000000 + (ts2.tv_nsec - ts1.tv_nsec);
237  alloctime = alloctime + timed;
238  #endif
239 
240  return tempmalloc;
241  }
242 }
G4ThreadLocal mspace tlms
Definition: hjmalloc.cc:9
void * mspace_malloc(mspace msp, size_t bytes)
Definition: mymalloc.cc:5061
#define TLMSSIZE
Definition: hjmalloc.cc:21
G4ThreadLocal int mallocswitch
Definition: hjmalloc.cc:8
G4ThreadLocal double alloctime
Definition: hjmalloc.cc:14
mspace create_mspace(size_t capacity, int locked)
Definition: mymalloc.cc:4974
G4ThreadLocal long int alloccount
Definition: hjmalloc.cc:11

Variable Documentation

G4ThreadLocal long int alloccount = 0

Definition at line 11 of file hjmalloc.cc.

Referenced by calloc(), malloc(), realloc(), and valloc().

G4ThreadLocal double alloctime = 0.0

Definition at line 14 of file hjmalloc.cc.

Referenced by calloc(), malloc(), realloc(), and valloc().

G4ThreadLocal long int freecount = 0

Definition at line 12 of file hjmalloc.cc.

Referenced by cfree(), free(), and realloc().

G4ThreadLocal double freetime = 0.0

Definition at line 15 of file hjmalloc.cc.

Referenced by cfree(), and free().

G4ThreadLocal int mallocswitch = 0

Definition at line 9 of file hjmalloc.cc.

Referenced by calloc(), cfree(), free(), malloc(), realloc(), and valloc().