Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreMemoryMacros.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 //---- ORIGINAL COPYRIGHT FOLLOWS -------------------------------------------
    00026 // ---------------------------------------------------------------------------------------------------------------------------------
    00027 // Copyright 2000, Paul Nettle. All rights reserved.
    00028 //
    00029 // You are free to use this source code in any commercial or non-commercial product.
    00030 //
    00031 // mmgr.cpp - Memory manager & tracking software
    00032 //
    00033 // The most recent version of this software can be found at: ftp://ftp.GraphicsPapers.com/pub/ProgrammingTools/MemoryManagers/
    00034 //
    00035 // [NOTE: Best when viewed with 8-character tabs]
    00036 //
    00037 // ---------------------------------------------------------------------------------------------------------------------------------
    00038
    00039 //-----------------------------------------------------------------------------
    00040 // How does this work?
    00041 // Remember that before the compiler starts to process a source file, it runs
    00042 // a neat tool called a preprocessor on it. What this preprocessor does in
    00043 // this case is replace all the instances of *alloc/free with the expanded
    00044 // macros - this way we cleverly replace all the calls to the standard C
    00045 // memory (de)allocation functions. The same is done for new/delete
    00046 //
    00047 // Of course, we have the drawback that we can't name a member function of
    00048 // a class *alloc or free and we can't overload the new/delete operators without
    00049 // first undefining these macros - ah, a C++ preprocessor with RE replacement,
    00050 // that would be a dream come true :)
    00051 //
    00052 #ifndef OGRE_MEMORY_MACROS
    00053 #define OGRE_MEMORY_MACROS
    00054
    00055 #if OGRE_DEBUG_MEMORY_MANAGER && OGRE_DEBUG_MODE
    00056 #   define new    (::Ogre::MemoryManager::sMemManager.setOwner(__FILE__,__LINE__,__FUNCTION__),false) ? NULL                                                 : new
    00057 #   define delete (::Ogre::MemoryManager::sMemManager.setOwner(__FILE__,__LINE__,__FUNCTION__),false) ? ::Ogre::MemoryManager::sMemManager.setOwner("",0,"") : delete
    00058 #   define malloc(sz)      ::Ogre::MemoryManager::sMemManager.allocMem(__FILE__,__LINE__,__FUNCTION__, m_alloc_malloc, sz,      gProcessID)
    00059 #   define calloc(sz)      ::Ogre::MemoryManager::sMemManager.allocMem(__FILE__,__LINE__,__FUNCTION__, m_alloc_calloc, sz,      gProcessID)
    00060 #   define realloc(ptr,sz) ::Ogre::MemoryManager::sMemManager.rllocMem(__FILE__,__LINE__,__FUNCTION__, m_alloc_realloc,sz, ptr, gProcessID)
    00061 #   define free(ptr)       ::Ogre::MemoryManager::sMemManager.dllocMem(__FILE__,__LINE__,__FUNCTION__, m_alloc_free,       ptr, gProcessID)
    00062 #else
    00063 #   define new new
    00064 #   define delete delete
    00065 #   define malloc( sz ) ::Ogre::MemoryManager::sMemManager.allocMem( __FILE__, __LINE__, sz )
    00066 #   define free( ptr ) ::Ogre::MemoryManager::sMemManager.dllocMem( __FILE__, __LINE__, ptr )
    00067 #   define realloc( ptr, sz ) ::Ogre::MemoryManager::sMemManager.rllocMem( __FILE__, __LINE__, ptr, sz )
    00068 #   define calloc( cnt, sz ) ::Ogre::MemoryManager::sMemManager.cllocMem( __FILE__, __LINE__, cnt, sz )
    00069 #endif // OGRE_DEBUG_MEMORY_MANAGER
    00070
    00071 #endif // OGRE_MEMORY_MACROS
    00072 //-----------------------------------------------------------------------------

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:33 2004