UTMemDebug.h

Go to the documentation of this file.
00001 //==================================================================================================
00002 // Copyright (C) 2010  Brian Tietz    sdbtietz at yahoo dot com
00003 //
00004 // This program is free software; you can redistribute it and/or modify it under the terms of the
00005 // GNU General Public License as published by the Free Software Foundation, version 2.0 of the
00006 // License.
00007 //
00008 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00010 // General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU General Public License along with this program; if
00013 // not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00014 // 02110-1301, USA.
00015 //
00016 // For commercial software, the copyright holder (Brian Tietz, email sdbtietz at yahoo dot com)
00017 // reserves the right and is willing to waive the proprietary source code disclosure aspects of that
00018 // license as applied to the UT library in exchange for either substantial contributions to the
00019 // development of the UT library or other forms of compensation.  Any such waiver must be
00020 // established in writing between the copyright holder and the commercial entity obtaining such a
00021 // waiver.
00022 //==================================================================================================
00023 
00024 
00025 #ifndef _UT_H_
00026 #error "DO NOT INCLUDE THIS FILE - INCLUDE UT.h INSTEAD"
00027 #endif
00028 
00029 
00030 EXTERN_C_BEGIN
00031 
00032 extern UT_EXPORT void*  malloc_MEMDEBUG(size_t size);
00033 extern UT_EXPORT void   free_MEMDEBUG(void* ptr);
00034 extern UT_EXPORT void*  calloc_MEMDEBUG( size_t num, size_t size );
00035 extern UT_EXPORT void*  realloc_MEMDEBUG( void* ptr, size_t size );
00036 
00037 #define malloc          malloc_MEMDEBUG
00038 #define free            free_MEMDEBUG
00039 #define calloc          calloc_MEMDEBUG
00040 #define realloc         realloc_MEMDEBUG
00041 
00042 EXTERN_C_END
00043 
00044 
00045 #if __cplusplus
00046 
00047 inline void*
00048 operator new(size_t size)
00049 {
00050     void* buffer = malloc_MEMDEBUG(size);
00051     if(!buffer)
00052         throw std::bad_alloc();
00053     return buffer;
00054 }
00055 
00056 
00057 inline void*
00058 operator new( size_t size, std::nothrow_t const& )
00059 {
00060     return malloc_MEMDEBUG(size);
00061 }
00062 
00063 
00064 inline void*
00065 operator new[](size_t size)
00066 {
00067     void* buffer = malloc_MEMDEBUG(size);
00068     if(!buffer)
00069         throw std::bad_alloc();
00070     return buffer;
00071 }
00072 
00073 
00074 inline void*
00075 operator new[]( size_t size, std::nothrow_t const& )
00076 {
00077     return malloc_MEMDEBUG(size);
00078 }
00079 
00080 
00081 inline void
00082 operator delete(void* p)
00083 {
00084     free_MEMDEBUG(p);
00085 }
00086 
00087 inline void
00088 operator delete[](void* p)
00089 {
00090     free_MEMDEBUG(p);
00091 }
00092 
00093 
00094 #endif // __cplusplus

Generated on Tue Dec 14 22:35:05 2010 for UT library by  doxygen 1.6.1