Geant4 Cross Reference |
1 // see license file for original license. 1 // see license file for original license. 2 2 3 #ifndef tools_glutess_memalloc 3 #ifndef tools_glutess_memalloc 4 #define tools_glutess_memalloc 4 #define tools_glutess_memalloc 5 5 6 ////////////////////////////////////////////// 6 //////////////////////////////////////////////////////// 7 /// inlined C code : ///////////////////////// 7 /// inlined C code : /////////////////////////////////// 8 ////////////////////////////////////////////// 8 //////////////////////////////////////////////////////// 9 9 10 #ifdef TOOLS_MEM 10 #ifdef TOOLS_MEM 11 #include "../mem" 11 #include "../mem" 12 #include <cstdlib> 12 #include <cstdlib> 13 namespace tools { 13 namespace tools { 14 inline void* mem_alloc(size_t a_size){ 14 inline void* mem_alloc(size_t a_size){ 15 mem::increment(tools::s_malloc().c_str()); 15 mem::increment(tools::s_malloc().c_str()); 16 return ::malloc(a_size); 16 return ::malloc(a_size); 17 } 17 } 18 inline void* mem_realloc(void* a_ptr,size_t a_ 18 inline void* mem_realloc(void* a_ptr,size_t a_size){ 19 if(a_ptr==NULL) mem::increment(tools::s_mall 19 if(a_ptr==NULL) mem::increment(tools::s_malloc().c_str()); 20 return ::realloc(a_ptr,a_size); 20 return ::realloc(a_ptr,a_size); 21 } 21 } 22 inline void mem_free(void* a_ptr){ 22 inline void mem_free(void* a_ptr){ 23 if(a_ptr!=NULL) mem::decrement(tools::s_mall 23 if(a_ptr!=NULL) mem::decrement(tools::s_malloc().c_str()); 24 ::free(a_ptr); 24 ::free(a_ptr); 25 } 25 } 26 inline int mem_init( size_t /*maxFast*/) {retu 26 inline int mem_init( size_t /*maxFast*/) {return 1;} 27 27 28 } 28 } 29 #else 29 #else 30 #include <cstdlib> 30 #include <cstdlib> 31 #include <cstring> 31 #include <cstring> 32 namespace tools { 32 namespace tools { 33 inline void* mem_alloc(size_t a_size) {return 33 inline void* mem_alloc(size_t a_size) {return ::memset( ::malloc( a_size ), 0xa5, a_size);} 34 inline void* mem_realloc(void* a_ptr,size_t a_ 34 inline void* mem_realloc(void* a_ptr,size_t a_size){return ::realloc(a_ptr,a_size);} 35 inline void mem_free(void* a_ptr){::free(a_ptr 35 inline void mem_free(void* a_ptr){::free(a_ptr);} 36 inline int mem_init( size_t /*maxFast*/) {retu 36 inline int mem_init( size_t /*maxFast*/) {return 1;} 37 } 37 } 38 #endif 38 #endif 39 39 40 #define memAlloc tools::mem_alloc 40 #define memAlloc tools::mem_alloc 41 #define memRealloc tools::mem_realloc 41 #define memRealloc tools::mem_realloc 42 #define memFree tools::mem_free 42 #define memFree tools::mem_free 43 #define memInit tools::mem_init 43 #define memInit tools::mem_init 44 44 45 #endif 45 #endif