Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/cmemT is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_cmemT
0005 #define tools_cmemT
0006 
0007 #include <cstdlib>
0008 
0009 #ifdef TOOLS_MEM
0010 #include "mem"
0011 #endif
0012 
0013 namespace tools {
0014 
0015 template <class T>
0016 inline void cmem_free(T*& a_p){
0017   if(!a_p) return;
0018   ::free(a_p);
0019   a_p = NULL;
0020 #ifdef TOOLS_MEM
0021   mem::decrement("cmem");
0022 #endif
0023 }
0024 
0025 template <class T>
0026 inline T* cmem_alloc(size_t a_num){
0027   if(a_num<=0) return 0;
0028   T* p = (T*)::malloc(a_num*sizeof(T));
0029   if(!p) return 0;
0030 #ifdef TOOLS_MEM
0031   mem::increment("cmem");
0032 #endif
0033   return p;
0034 }
0035 
0036 template <class T>
0037 inline T* cmem_alloc_copy(const T* a_from,size_t a_num){
0038   if(a_num<=0) return 0;
0039   T* p = (T*)::malloc(a_num*sizeof(T));
0040   if(!p) return 0;
0041 #ifdef TOOLS_MEM
0042   mem::increment("cmem");
0043 #endif
0044   //::memcpy(p,a_from,a_num*sizeof(T));
0045   for(size_t i=0;i<a_num;i++) p[i] = a_from[i];
0046   return p;
0047 }
0048 
0049 }
0050 
0051 #endif