// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_cmemT #define tools_cmemT #include #ifdef TOOLS_MEM #include "mem" #endif namespace tools { template inline void cmem_free(T*& a_p){ if(!a_p) return; ::free(a_p); a_p = NULL; #ifdef TOOLS_MEM mem::decrement("cmem"); #endif } template inline T* cmem_alloc(size_t a_num){ if(a_num<=0) return 0; T* p = (T*)::malloc(a_num*sizeof(T)); if(!p) return 0; #ifdef TOOLS_MEM mem::increment("cmem"); #endif return p; } template inline T* cmem_alloc_copy(const T* a_from,size_t a_num){ if(a_num<=0) return 0; T* p = (T*)::malloc(a_num*sizeof(T)); if(!p) return 0; #ifdef TOOLS_MEM mem::increment("cmem"); #endif //::memcpy(p,a_from,a_num*sizeof(T)); for(size_t i=0;i