00001 //******************************************************************************* 00002 // 00003 // ******* *** *** * 00004 // * * * * 00005 // * * * ***** 00006 // * * *** * * ** * ** *** 00007 // * * * * * * * **** * * * 00008 // * * * * * * * * * * * 00009 // * *** *** * ** ** ** * * 00010 // * 00011 //******************************************************************************* 00012 // see http://sourceforge.net/projects/tcsystem/ for details. 00013 // Copyright (C) 2003 - 2008 Thomas Goessler. All Rights Reserved. 00014 //******************************************************************************* 00015 // 00016 // TCSystem is the legal property of its developers. 00017 // Please refer to the COPYRIGHT file distributed with this source distribution. 00018 // 00019 // This library is free software; you can redistribute it and/or 00020 // modify it under the terms of the GNU Lesser General Public 00021 // License as published by the Free Software Foundation; either 00022 // version 2.1 of the License, or (at your option) any later version. 00023 // 00024 // This library is distributed in the hope that it will be useful, 00025 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00027 // Lesser General Public License for more details. 00028 // 00029 // You should have received a copy of the GNU Lesser General Public 00030 // License along with this library; if not, write to the Free Software 00031 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00032 //******************************************************************************* 00033 // $Id: TCNew.h 870 2008-07-21 14:15:33Z the_____tiger $ 00034 //******************************************************************************* 00035 #ifndef _TCNEW_H_ 00036 #define _TCNEW_H_ 00037 00038 #include "TCNonCopyable.h" 00039 00040 namespace TC 00041 { 00042 class NewPointer; 00043 00060 class TCBASE_API New: protected NonCopyAble 00061 { 00062 public: 00066 static New* GetInstance() 00067 { 00068 static New m; return m_instance; 00069 } 00071 inline bool CheckMemory() const { return m_check_memory; } 00073 void EnableMemoryChecking(); 00074 00076 void* Allocate(uint32 size, const char *fileName, sint32 line); 00078 void Free(void *pointer); 00079 00081 void PrintCurrentMemoryAllocation(); 00083 void PrintMemoryLeaks(); 00084 00086 ~New(); 00087 00088 private: 00090 New(); 00091 00092 private: 00094 uint64 m_num_allocate_calls; 00096 uint64 m_num_allocated_pointers; 00098 uint64 m_max_num_allocated_pointers; 00100 uint64 m_max_num_allocated_bytes; 00102 uint64 m_num_allocated_bytes; 00104 bool m_check_memory; 00105 00107 NewPointer* m_first_pointer; 00109 NewPointer* m_last_pointer; 00110 00112 static New *m_instance; 00113 00114 }; 00115 00120 } 00121 00122 #endif // _TCNEW_H_