#ifndef _TRACK_MEM_H_ #define _TRACK_MEM_H_ #include #include template class track_mem { #ifdef DEBUG_ALLOCATIONS private: static const char *name; static int ref_count; public: track_mem(const char *n="unknown") { name=n; fprintf(stderr,"%s #%d: allocated 0x%lx bytes at 0x%p\n",name,++ref_count,sizeof(T),this); fflush(stderr); }; ~track_mem() { fprintf(stderr,"%s #%d: freed 0x%lx bytes at 0x%p\n",name,this->ref_count--,sizeof(T),this); fflush(stderr); }; #else public: track_mem(const char *n=0) {}; ~track_mem() {}; #endif }; #ifdef DEBUG_ALLOCATIONS template const char *track_mem::name; template int track_mem::ref_count; #endif #endif